1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 08:08:12 +00:00

Kernel: Stop swallowing thread unblocks while process is stopped

This easily led to kernel deadlocks if the stopped thread held an
important global mutex (like the disk cache lock) while blocking.
Resolve this by ensuring stopped threads have a chance to return to the
userland boundary before actually stopping.
This commit is contained in:
Idan Horowitz 2024-02-09 21:13:41 +02:00 committed by Andreas Kling
parent 458e990b7b
commit e38ccebfc8
4 changed files with 24 additions and 23 deletions

View file

@ -268,9 +268,14 @@ void Scheduler::context_switch(Thread* thread)
return;
// If the last process hasn't blocked (still marked as running),
// mark it as runnable for the next round.
if (from_thread->state() == Thread::State::Running)
from_thread->set_state(Thread::State::Runnable);
// mark it as runnable for the next round, unless it's supposed
// to be stopped, in which case just mark it as such.
if (from_thread->state() == Thread::State::Running) {
if (from_thread->should_be_stopped())
from_thread->set_state(Thread::State::Stopped);
else
from_thread->set_state(Thread::State::Runnable);
}
#ifdef LOG_EVERY_CONTEXT_SWITCH
auto const msg = "Scheduler[{}]: {} -> {} [prio={}] {:p}";