Browse Source

kernel: avoid racy behavior in global suspension

nce_cpp
Liam 3 years ago
parent
commit
ae2bfd082b
  1. 20
      src/core/hle/kernel/kernel.cpp

20
src/core/hle/kernel/kernel.cpp

@ -1109,15 +1109,27 @@ void KernelCore::Suspend(bool suspended) {
const bool should_suspend{exception_exited || suspended}; const bool should_suspend{exception_exited || suspended};
const auto activity = should_suspend ? ProcessActivity::Paused : ProcessActivity::Runnable; const auto activity = should_suspend ? ProcessActivity::Paused : ProcessActivity::Runnable;
for (auto* process : GetProcessList()) {
std::vector<KScopedAutoObject<KThread>> process_threads;
{
KScopedSchedulerLock sl{*this};
if (auto* process = CurrentProcess(); process != nullptr) {
process->SetActivity(activity); process->SetActivity(activity);
if (should_suspend) {
// Wait for execution to stop
if (!should_suspend) {
// Runnable now; no need to wait.
return;
}
for (auto* thread : process->GetThreadList()) { for (auto* thread : process->GetThreadList()) {
thread->WaitUntilSuspended();
process_threads.emplace_back(thread);
}
} }
} }
// Wait for execution to stop.
for (auto& thread : process_threads) {
thread->WaitUntilSuspended();
} }
} }

Loading…
Cancel
Save