CPUThread.cpp: Fix use of cpu_counter::add

This also fixes a crash when saving savestate because main thread uses cpu_counter::suspend_all which adds cuncurrency.
This commit is contained in:
Eladash 2023-07-22 06:08:35 +03:00 committed by Elad Ashkenazi
parent 9ff91c29f2
commit c44cddabfa

View file

@ -789,6 +789,19 @@ bool cpu_thread::check_state() noexcept
return store;
}
if (s_tls_thread_slot == umax)
{
if (cpu_flag::wait - state)
{
// Force wait flag (must be set during ownership of s_cpu_lock), this makes the atomic op fail as a side effect
state += cpu_flag::wait;
store = true;
}
// Restore thread in the suspend list
cpu_counter::add(this);
}
if (flags & cpu_flag::wait)
{
flags -= cpu_flag::wait;
@ -843,12 +856,6 @@ bool cpu_thread::check_state() noexcept
if (escape)
{
if (s_tls_thread_slot == umax && !retval)
{
// Restore thread in the suspend list
cpu_counter::add(this);
}
if (cpu_can_stop && state0 & cpu_flag::pending)
{
// Execute pending work