BarryServer : Git

All the code for all my projects
// BarryServer : Git / Nucleus / blob / 4760662b4aefcc8d41b04e8920f71583846594b1 / task / exit.c

// Related

Nucleus

Barry Signals and small task functions 9d6eb50 (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/panic.h>
#include <nucleus/task.h>

extern ObjectList *readyQueue[];

/* Terminate the current task */
_Noreturn void
terminate(void)
{
	current->state = TERMINATED;
	current->inCriticalSection = 0;

	/* Unblock waiting tasks */
	Task *tmp;
	while (current->wait && count(current->wait)) {
		tmp = pop_from_start(current->wait);
		add(readyQueue[tmp->priority], 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();
}