~sircmpwn/helios

ref: 673c27e57684deeedbe88e1e6b7b940fdca5fc87 helios/sched/tasks.ha -rw-r--r-- 1.2 KiB
673c27e5Drew DeVault vulcan: add (basic) cspace tests 1 year, 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use arch;
use arch::mem;
use objects;
use log;

// TODO: Store these globals with physical addresses

// The currently running process. Not valid during system initialization.
export let active: *objects::taskstate = null: *objects::taskstate;

// Linked list of active tasks. Not valid during system initialization.
export let tasks: *objects::taskstate = null: *objects::taskstate;

// Adds a new task to the linked list of active tasks.
export fn addtask(state: *objects::taskstate) void = {
	let head = tasks;
	state.prev = null;
	state.next = head;

	if (head == null) {
		tasks = state;
	} else {
		tasks = state;
		head.prev = state;
	};
};

// Removes a task from the list of active tasks.
export fn rmtask(state: *objects::taskstate) void = {
	match (state.prev) {
	case let prev: *objects::taskstate =>
		prev.next = state.next;
	case null =>
		match (state.next) {
		case null =>
			log::printfln("Warning: last task terminated, entering permanent idle");
			for (true) arch::pause();
		case let task: *objects::taskstate =>
			tasks = task;
		};
	};
	match (state.next) {
	case let next: *objects::taskstate =>
		next.prev = state.prev;
	case null =>
		yield;
	};

	if (state == active) {
		yieldtask();
	};
};