From 2bc9e09456ed544efba044a4734a8ef2d960aa08 Mon Sep 17 00:00:00 2001 From: Silent Date: Sun, 18 Aug 2019 14:51:18 +0200 Subject: [PATCH 1/2] Core/CPU: Do not yield to UI from CPU methods Core::RunAsCPUThread may be called from Qt signals, and if code yields to UI there then it results in infinite recursion --- Source/Core/Core/HW/CPU.cpp | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/Source/Core/Core/HW/CPU.cpp b/Source/Core/Core/HW/CPU.cpp index b8243a0452..28fabff2fb 100644 --- a/Source/Core/Core/HW/CPU.cpp +++ b/Source/Core/Core/HW/CPU.cpp @@ -183,10 +183,7 @@ void Stop() while (s_state_cpu_thread_active) { - std::cv_status status = - s_state_cpu_idle_cvar.wait_for(state_lock, std::chrono::milliseconds(100)); - if (status == std::cv_status::timeout) - Host_YieldToUI(); + s_state_cpu_idle_cvar.wait(state_lock); } RunAdjacentSystems(false); @@ -252,10 +249,7 @@ void EnableStepping(bool stepping) while (s_state_cpu_thread_active) { - std::cv_status status = - s_state_cpu_idle_cvar.wait_for(state_lock, std::chrono::milliseconds(100)); - if (status == std::cv_status::timeout) - Host_YieldToUI(); + s_state_cpu_idle_cvar.wait(state_lock); } RunAdjacentSystems(false); @@ -303,10 +297,7 @@ bool PauseAndLock(bool do_lock, bool unpause_on_unlock, bool control_adjacent) while (s_state_cpu_thread_active) { - std::cv_status status = - s_state_cpu_idle_cvar.wait_for(state_lock, std::chrono::milliseconds(100)); - if (status == std::cv_status::timeout) - Host_YieldToUI(); + s_state_cpu_idle_cvar.wait(state_lock); } if (control_adjacent) From 23f335ba91fbb7fbb0ced3486c6eaf120fa653bf Mon Sep 17 00:00:00 2001 From: Silent Date: Sun, 18 Aug 2019 14:53:43 +0200 Subject: [PATCH 2/2] Core/CPU: Make use of type deduction for scoped locks --- Source/Core/Core/HW/CPU.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Source/Core/Core/HW/CPU.cpp b/Source/Core/Core/HW/CPU.cpp index 28fabff2fb..b708263bfc 100644 --- a/Source/Core/Core/HW/CPU.cpp +++ b/Source/Core/Core/HW/CPU.cpp @@ -87,7 +87,7 @@ static void ExecutePendingJobs(std::unique_lock& state_lock) void Run() { - std::unique_lock state_lock(s_state_change_lock); + std::unique_lock state_lock(s_state_change_lock); while (s_state != State::PowerDown) { s_state_cpu_cvar.wait(state_lock, [] { return !s_state_paused_and_locked; }); @@ -177,7 +177,7 @@ void Stop() // Change state and wait for it to be acknowledged. // We don't need the stepping lock because State::PowerDown is a priority state which // will stick permanently. - std::unique_lock state_lock(s_state_change_lock); + std::unique_lock state_lock(s_state_change_lock); s_state = State::PowerDown; s_state_cpu_cvar.notify_one(); @@ -211,7 +211,7 @@ void Reset() void StepOpcode(Common::Event* event) { - std::lock_guard state_lock(s_state_change_lock); + std::lock_guard state_lock(s_state_change_lock); // If we're not stepping then this is pointless if (!IsStepping()) { @@ -240,8 +240,8 @@ static bool SetStateLocked(State s) void EnableStepping(bool stepping) { - std::lock_guard stepping_lock(s_stepping_lock); - std::unique_lock state_lock(s_state_change_lock); + std::lock_guard stepping_lock(s_stepping_lock); + std::unique_lock state_lock(s_state_change_lock); if (stepping) { @@ -263,7 +263,7 @@ void EnableStepping(bool stepping) void Break() { - std::lock_guard state_lock(s_state_change_lock); + std::lock_guard state_lock(s_state_change_lock); // If another thread is trying to PauseAndLock then we need to remember this // for later to ignore the unpause_on_unlock. @@ -289,7 +289,7 @@ bool PauseAndLock(bool do_lock, bool unpause_on_unlock, bool control_adjacent) { s_stepping_lock.lock(); - std::unique_lock state_lock(s_state_change_lock); + std::unique_lock state_lock(s_state_change_lock); s_state_paused_and_locked = true; was_unpaused = s_state == State::Running; @@ -322,7 +322,7 @@ bool PauseAndLock(bool do_lock, bool unpause_on_unlock, bool control_adjacent) } { - std::lock_guard state_lock(s_state_change_lock); + std::lock_guard state_lock(s_state_change_lock); if (s_state_system_request_stepping) { s_state_system_request_stepping = false; @@ -344,7 +344,7 @@ bool PauseAndLock(bool do_lock, bool unpause_on_unlock, bool control_adjacent) void AddCPUThreadJob(std::function function) { - std::unique_lock state_lock(s_state_change_lock); + std::unique_lock state_lock(s_state_change_lock); s_pending_jobs.push(std::move(function)); }