From 48d48fe1af09e437f574a5fb3d6a5b62a146e08a Mon Sep 17 00:00:00 2001 From: Dentomologist Date: Sun, 4 Jun 2023 13:07:43 -0700 Subject: [PATCH] CPUManager: Remove unnecessary PauseAndLock parameters CPUManager::PauseAndLock is now only called with do_lock=true, and unpause_on_unlock only ever was used when do_lock is false (which is now handled in RestoreStateAndUnlock instead), so both parameters are unnecessary. --- Source/Core/Core/Core.cpp | 2 +- Source/Core/Core/HW/CPU.cpp | 45 +++++++++++++++++-------------------- Source/Core/Core/HW/CPU.h | 2 +- 3 files changed, 22 insertions(+), 27 deletions(-) diff --git a/Source/Core/Core/Core.cpp b/Source/Core/Core/Core.cpp index 6a949f147ca..2b005374ada 100644 --- a/Source/Core/Core/Core.cpp +++ b/Source/Core/Core/Core.cpp @@ -781,7 +781,7 @@ static bool PauseAndLock(Core::System& system, bool do_lock, bool unpause_on_unl // first pause the CPU // This acquires a wrapper mutex and converts the current thread into // a temporary replacement CPU Thread. - was_unpaused = system.GetCPU().PauseAndLock(true, true, false); + was_unpaused = system.GetCPU().PauseAndLock(false); } // audio has to come after CPU, because CPU thread can wait for audio thread (m_throttle). diff --git a/Source/Core/Core/HW/CPU.cpp b/Source/Core/Core/HW/CPU.cpp index 02e45de595e..9942478cb2d 100644 --- a/Source/Core/Core/HW/CPU.cpp +++ b/Source/Core/Core/HW/CPU.cpp @@ -351,36 +351,31 @@ void CPUManager::Continue() Core::NotifyStateChanged(Core::State::Running); } -bool CPUManager::PauseAndLock(bool do_lock, bool unpause_on_unlock, bool control_adjacent) +bool CPUManager::PauseAndLock(const bool control_adjacent) { - bool was_unpaused = false; + m_stepping_lock.lock(); - if (do_lock) + std::unique_lock state_lock(m_state_change_lock); + m_state_paused_and_locked = true; + + const bool was_unpaused = m_state == State::Running; + SetStateLocked(State::Stepping); + + while (m_state_cpu_thread_active) { - m_stepping_lock.lock(); + m_state_cpu_idle_cvar.wait(state_lock); + } - std::unique_lock state_lock(m_state_change_lock); - m_state_paused_and_locked = true; + if (control_adjacent) + RunAdjacentSystems(false); + state_lock.unlock(); - was_unpaused = m_state == State::Running; - SetStateLocked(State::Stepping); - - while (m_state_cpu_thread_active) - { - m_state_cpu_idle_cvar.wait(state_lock); - } - - if (control_adjacent) - RunAdjacentSystems(false); - state_lock.unlock(); - - // NOTE: It would make more sense for Core::DeclareAsCPUThread() to keep a - // depth counter instead of being a boolean. - if (!Core::IsCPUThread()) - { - m_have_fake_cpu_thread = true; - Core::DeclareAsCPUThread(); - } + // NOTE: It would make more sense for Core::DeclareAsCPUThread() to keep a + // depth counter instead of being a boolean. + if (!Core::IsCPUThread()) + { + m_have_fake_cpu_thread = true; + Core::DeclareAsCPUThread(); } return was_unpaused; diff --git a/Source/Core/Core/HW/CPU.h b/Source/Core/Core/HW/CPU.h index 104a83204ad..b6eea7f052a 100644 --- a/Source/Core/Core/HW/CPU.h +++ b/Source/Core/Core/HW/CPU.h @@ -95,7 +95,7 @@ public: // Cannot be used by System threads as it will deadlock. It is threadsafe otherwise. // "control_adjacent" causes PauseAndLock to behave like SetStepping by modifying the // state of the Audio and FIFO subsystems as well. - bool PauseAndLock(bool do_lock, bool unpause_on_unlock, bool control_adjacent); + bool PauseAndLock(bool control_adjacent); void RestoreStateAndUnlock(bool unpause_on_unlock, bool control_adjacent); // Adds a job to be executed during on the CPU thread. This should be combined with