VERY experimental Nintendo Switch 2 emulator
C++
kernel: avoid racy behavior in global suspension
Liamae2bfd082b0a
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cppindex 09c36ee09d..6df77b4239 100644--- a/src/core/hle/kernel/kernel.cpp+++ b/src/core/hle/kernel/kernel.cpp@@ -1109,16 +1109,28 @@ void KernelCore::Suspend(bool suspended) {const bool should_suspend{exception_exited || suspended};const auto activity = should_suspend ? ProcessActivity::Paused : ProcessActivity::Runnable;- for (auto* process : GetProcessList()) {- process->SetActivity(activity);+ std::vector<KScopedAutoObject<KThread>> process_threads;+ {+ KScopedSchedulerLock sl{*this};++ if (auto* process = CurrentProcess(); process != nullptr) {+ process->SetActivity(activity);++ if (!should_suspend) {+ // Runnable now; no need to wait.+ return;+ }- if (should_suspend) {- // Wait for execution to stopfor (auto* thread : process->GetThreadList()) {- thread->WaitUntilSuspended();+ process_threads.emplace_back(thread);}}}++ // Wait for execution to stop.+ for (auto& thread : process_threads) {+ thread->WaitUntilSuspended();+ }}void KernelCore::ShutdownCores() {