CPU: Extract RestoreStateAndUnlock from PauseAndLock

Replace call of CPUManager::PauseAndLock(do_lock=false) with new
function RestoreStateAndUnlock for clarity.

Callers of Core::PauseAndLock ignore the return value when do_lock is
false, so in that case was_unpaused in Core::PauseAndLock doesn't need
to be set and so RestoreStateAndUnlock doesn't need to return anything.
This commit is contained in:
Dentomologist
2023-06-04 11:53:38 -07:00
parent bebeba29c3
commit 691743fbc4
3 changed files with 30 additions and 27 deletions

View File

@@ -801,7 +801,7 @@ static bool PauseAndLock(Core::System& system, bool do_lock, bool unpause_on_unl
// mechanism to unpause them. If we unpaused the systems above when releasing
// the locks then they could call CPU::Break which would require detecting it
// and re-pausing with CPU::SetStepping.
was_unpaused = system.GetCPU().PauseAndLock(false, unpause_on_unlock, true);
system.GetCPU().RestoreStateAndUnlock(unpause_on_unlock, true);
}
return was_unpaused;

View File

@@ -382,36 +382,38 @@ bool CPUManager::PauseAndLock(bool do_lock, bool unpause_on_unlock, bool control
Core::DeclareAsCPUThread();
}
}
else
{
// Only need the stepping lock for this
if (m_have_fake_cpu_thread)
{
m_have_fake_cpu_thread = false;
Core::UndeclareAsCPUThread();
}
{
std::lock_guard state_lock(m_state_change_lock);
if (m_state_system_request_stepping)
{
m_state_system_request_stepping = false;
}
else if (unpause_on_unlock && SetStateLocked(State::Running))
{
was_unpaused = true;
}
m_state_paused_and_locked = false;
m_state_cpu_cvar.notify_one();
if (control_adjacent)
RunAdjacentSystems(m_state == State::Running);
}
m_stepping_lock.unlock();
}
return was_unpaused;
}
void CPUManager::RestoreStateAndUnlock(const bool unpause_on_unlock, const bool control_adjacent)
{
// Only need the stepping lock for this
if (m_have_fake_cpu_thread)
{
m_have_fake_cpu_thread = false;
Core::UndeclareAsCPUThread();
}
{
std::lock_guard state_lock(m_state_change_lock);
if (m_state_system_request_stepping)
{
m_state_system_request_stepping = false;
}
else if (unpause_on_unlock)
{
SetStateLocked(State::Running);
}
m_state_paused_and_locked = false;
m_state_cpu_cvar.notify_one();
if (control_adjacent)
RunAdjacentSystems(m_state == State::Running);
}
m_stepping_lock.unlock();
}
void CPUManager::AddCPUThreadJob(Common::MoveOnlyFunction<void()> function)
{
std::unique_lock state_lock(m_state_change_lock);

View File

@@ -96,6 +96,7 @@ public:
// "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 = true, bool control_adjacent = false);
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
// PauseAndLock(), as while the CPU is in the run loop, it won't execute the function.