Nucleus
Barry Per-CPU Scheduler bb0cb77 (3 years, 2 months ago)
/*
* This file handles task termination and contains the exit() system call. It
* destroys a task and releases all resources it holds, notifies any waiting
* tasks and the parent.
*/
#include <nucleus/kernel.h>
#include <nucleus/task.h>
/* Terminate the current task */
_Noreturn void
terminate(void)
{
current->state = TERMINATED;
/* Unblock waiting tasks */
Task *tmp;
while (current->wait && count(current->wait)) {
tmp = pop_from_start(current->wait);
unblock_task(tmp);
put(tmp);
}
schedule();
__builtin_unreachable();
}
/* Exit the current task */
_Noreturn void
exit(int status)
{
if (current->tid == 1)
panic("Attempted to exit init! Exit code %d", status);
current->status = (1 << 31) | (status & 0x0F);
terminate();
}