kernel: avoid racy behavior in global suspension
This commit is contained in:
parent
9fc1bcc7b2
commit
85527cc7c7
1 changed files with 17 additions and 5 deletions
|
@ -1109,17 +1109,29 @@ 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) {
|
if (!should_suspend) {
|
||||||
// Wait for execution to stop
|
// Runnable now; no need to wait.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (auto* thread : process->GetThreadList()) {
|
for (auto* thread : process->GetThreadList()) {
|
||||||
|
process_threads.emplace_back(thread);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait for execution to stop.
|
||||||
|
for (auto& thread : process_threads) {
|
||||||
thread->WaitUntilSuspended();
|
thread->WaitUntilSuspended();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void KernelCore::ShutdownCores() {
|
void KernelCore::ShutdownCores() {
|
||||||
KScopedSchedulerLock lk{*this};
|
KScopedSchedulerLock lk{*this};
|
||||||
|
|
Loading…
Reference in a new issue