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

Kernel: Add a Finalizer process to take care of dying processes.

Instead of processes themselves getting scheduled to finish dying,
let's have a Finalizer process that wakes up whenever someone is dying.
This way we can do all kinds of lock-taking in process cleanup without
risking reentering the scheduler.
This commit is contained in:
Andreas Kling 2019-02-06 18:45:21 +01:00
parent e05237485c
commit 6cba80510e
5 changed files with 59 additions and 23 deletions

View file

@ -12,6 +12,7 @@ static const dword time_slice = 5; // *10 = 50ms
Process* current;
Process* g_last_fpu_process;
Process* g_finalizer;
static Process* s_colonel_process;
struct TaskRedirectionData {
@ -127,6 +128,13 @@ bool Scheduler::pick_next()
return true;
}
if (process.state() == Process::Dying) {
ASSERT(g_finalizer);
if (g_finalizer->state() == Process::BlockedLurking)
g_finalizer->unblock();
return true;
}
return true;
});
@ -170,7 +178,7 @@ bool Scheduler::pick_next()
g_processes->append(g_processes->remove_head());
auto* process = g_processes->head();
if (process->state() == Process::Runnable || process->state() == Process::Running || process->state() == Process::Dying) {
if (process->state() == Process::Runnable || process->state() == Process::Running) {
#ifdef SCHEDULER_DEBUG
dbgprintf("switch to %s(%u) @ %w:%x\n", process->name().characters(), process->pid(), process->tss().cs, process->tss().eip);
#endif