Merge pull request #8320 from CookiePLMonster/cpu-lock-yield-fix
Do not yield to UI from PauseAndLock
This commit is contained in:
commit
45ba745bc8
|
@ -87,7 +87,7 @@ static void ExecutePendingJobs(std::unique_lock<std::mutex>& state_lock)
|
||||||
|
|
||||||
void Run()
|
void Run()
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> state_lock(s_state_change_lock);
|
std::unique_lock state_lock(s_state_change_lock);
|
||||||
while (s_state != State::PowerDown)
|
while (s_state != State::PowerDown)
|
||||||
{
|
{
|
||||||
s_state_cpu_cvar.wait(state_lock, [] { return !s_state_paused_and_locked; });
|
s_state_cpu_cvar.wait(state_lock, [] { return !s_state_paused_and_locked; });
|
||||||
|
@ -177,16 +177,13 @@ void Stop()
|
||||||
// Change state and wait for it to be acknowledged.
|
// Change state and wait for it to be acknowledged.
|
||||||
// We don't need the stepping lock because State::PowerDown is a priority state which
|
// We don't need the stepping lock because State::PowerDown is a priority state which
|
||||||
// will stick permanently.
|
// will stick permanently.
|
||||||
std::unique_lock<std::mutex> state_lock(s_state_change_lock);
|
std::unique_lock state_lock(s_state_change_lock);
|
||||||
s_state = State::PowerDown;
|
s_state = State::PowerDown;
|
||||||
s_state_cpu_cvar.notify_one();
|
s_state_cpu_cvar.notify_one();
|
||||||
|
|
||||||
while (s_state_cpu_thread_active)
|
while (s_state_cpu_thread_active)
|
||||||
{
|
{
|
||||||
std::cv_status status =
|
s_state_cpu_idle_cvar.wait(state_lock);
|
||||||
s_state_cpu_idle_cvar.wait_for(state_lock, std::chrono::milliseconds(100));
|
|
||||||
if (status == std::cv_status::timeout)
|
|
||||||
Host_YieldToUI();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RunAdjacentSystems(false);
|
RunAdjacentSystems(false);
|
||||||
|
@ -214,7 +211,7 @@ void Reset()
|
||||||
|
|
||||||
void StepOpcode(Common::Event* event)
|
void StepOpcode(Common::Event* event)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> 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 we're not stepping then this is pointless
|
||||||
if (!IsStepping())
|
if (!IsStepping())
|
||||||
{
|
{
|
||||||
|
@ -243,8 +240,8 @@ static bool SetStateLocked(State s)
|
||||||
|
|
||||||
void EnableStepping(bool stepping)
|
void EnableStepping(bool stepping)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> stepping_lock(s_stepping_lock);
|
std::lock_guard stepping_lock(s_stepping_lock);
|
||||||
std::unique_lock<std::mutex> state_lock(s_state_change_lock);
|
std::unique_lock state_lock(s_state_change_lock);
|
||||||
|
|
||||||
if (stepping)
|
if (stepping)
|
||||||
{
|
{
|
||||||
|
@ -252,10 +249,7 @@ void EnableStepping(bool stepping)
|
||||||
|
|
||||||
while (s_state_cpu_thread_active)
|
while (s_state_cpu_thread_active)
|
||||||
{
|
{
|
||||||
std::cv_status status =
|
s_state_cpu_idle_cvar.wait(state_lock);
|
||||||
s_state_cpu_idle_cvar.wait_for(state_lock, std::chrono::milliseconds(100));
|
|
||||||
if (status == std::cv_status::timeout)
|
|
||||||
Host_YieldToUI();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RunAdjacentSystems(false);
|
RunAdjacentSystems(false);
|
||||||
|
@ -269,7 +263,7 @@ void EnableStepping(bool stepping)
|
||||||
|
|
||||||
void Break()
|
void Break()
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> 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
|
// If another thread is trying to PauseAndLock then we need to remember this
|
||||||
// for later to ignore the unpause_on_unlock.
|
// for later to ignore the unpause_on_unlock.
|
||||||
|
@ -295,7 +289,7 @@ bool PauseAndLock(bool do_lock, bool unpause_on_unlock, bool control_adjacent)
|
||||||
{
|
{
|
||||||
s_stepping_lock.lock();
|
s_stepping_lock.lock();
|
||||||
|
|
||||||
std::unique_lock<std::mutex> state_lock(s_state_change_lock);
|
std::unique_lock state_lock(s_state_change_lock);
|
||||||
s_state_paused_and_locked = true;
|
s_state_paused_and_locked = true;
|
||||||
|
|
||||||
was_unpaused = s_state == State::Running;
|
was_unpaused = s_state == State::Running;
|
||||||
|
@ -303,10 +297,7 @@ bool PauseAndLock(bool do_lock, bool unpause_on_unlock, bool control_adjacent)
|
||||||
|
|
||||||
while (s_state_cpu_thread_active)
|
while (s_state_cpu_thread_active)
|
||||||
{
|
{
|
||||||
std::cv_status status =
|
s_state_cpu_idle_cvar.wait(state_lock);
|
||||||
s_state_cpu_idle_cvar.wait_for(state_lock, std::chrono::milliseconds(100));
|
|
||||||
if (status == std::cv_status::timeout)
|
|
||||||
Host_YieldToUI();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (control_adjacent)
|
if (control_adjacent)
|
||||||
|
@ -331,7 +322,7 @@ bool PauseAndLock(bool do_lock, bool unpause_on_unlock, bool control_adjacent)
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> state_lock(s_state_change_lock);
|
std::lock_guard state_lock(s_state_change_lock);
|
||||||
if (s_state_system_request_stepping)
|
if (s_state_system_request_stepping)
|
||||||
{
|
{
|
||||||
s_state_system_request_stepping = false;
|
s_state_system_request_stepping = false;
|
||||||
|
@ -353,7 +344,7 @@ bool PauseAndLock(bool do_lock, bool unpause_on_unlock, bool control_adjacent)
|
||||||
|
|
||||||
void AddCPUThreadJob(std::function<void()> function)
|
void AddCPUThreadJob(std::function<void()> function)
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> state_lock(s_state_change_lock);
|
std::unique_lock state_lock(s_state_change_lock);
|
||||||
s_pending_jobs.push(std::move(function));
|
s_pending_jobs.push(std::move(function));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue