1
0
Fork 1
forked from suyu/suyu

core: Use atomic instead of a lock to protect is_paused.

- This allows us to call IsPaused() elsewhere if we are holding the suspend lock.
This commit is contained in:
bunnei 2022-11-26 13:46:38 -08:00
parent 2572b0a5ea
commit 8f6245be9a

View file

@ -189,7 +189,7 @@ struct System::Impl {
kernel.Suspend(false); kernel.Suspend(false);
core_timing.SyncPause(false); core_timing.SyncPause(false);
is_paused = false; is_paused.store(false, std::memory_order_relaxed);
return status; return status;
} }
@ -200,14 +200,13 @@ struct System::Impl {
core_timing.SyncPause(true); core_timing.SyncPause(true);
kernel.Suspend(true); kernel.Suspend(true);
is_paused = true; is_paused.store(true, std::memory_order_relaxed);
return status; return status;
} }
bool IsPaused() const { bool IsPaused() const {
std::unique_lock lk(suspend_guard); return is_paused.load(std::memory_order_relaxed);
return is_paused;
} }
std::unique_lock<std::mutex> StallProcesses() { std::unique_lock<std::mutex> StallProcesses() {
@ -218,7 +217,7 @@ struct System::Impl {
} }
void UnstallProcesses() { void UnstallProcesses() {
if (!is_paused) { if (!IsPaused()) {
core_timing.SyncPause(false); core_timing.SyncPause(false);
kernel.Suspend(false); kernel.Suspend(false);
} }
@ -465,7 +464,7 @@ struct System::Impl {
} }
mutable std::mutex suspend_guard; mutable std::mutex suspend_guard;
bool is_paused{}; std::atomic_bool is_paused{};
std::atomic<bool> is_shutting_down{}; std::atomic<bool> is_shutting_down{};
Timing::CoreTiming core_timing; Timing::CoreTiming core_timing;