283
|
1 module process;
|
300
|
2
|
283
|
3 import memory;
|
|
4 import kernel;
|
|
5
|
|
6 // process type definition:
|
296
|
7 type struct {
|
283
|
8 int id;
|
292
|
9 int status;
|
407
|
10 process_t* next;
|
|
11 process_t* prev;
|
283
|
12 } process_t;
|
|
13
|
407
|
14 var process_t* first_process;
|
|
15 var process_t* last_process;
|
306
|
16 var int next_pid;
|
283
|
17
|
296
|
18 function void init()
|
283
|
19 {
|
|
20 next_pid = 0;
|
407
|
21 first_process = 0;
|
|
22 last_process = 0;
|
283
|
23 }
|
|
24
|
|
25 /*
|
|
26 Create a new process.
|
|
27 */
|
402
|
28 function process_t* create()
|
283
|
29 {
|
301
|
30 var process_t* p;
|
389
|
31
|
407
|
32 p = memory.alloc(sizeof(process_t));
|
283
|
33 p->id = next_pid;
|
393
|
34 p->status = 0; // Ready!
|
407
|
35 p->next = 0;
|
|
36 p->prev = 0;
|
389
|
37
|
|
38 // Increment PID:
|
300
|
39 next_pid = next_pid + 1;
|
389
|
40
|
407
|
41 return p;
|
|
42 }
|
|
43
|
|
44 function void enqueue(process_t* p)
|
|
45 {
|
389
|
46 // Store it in the list:
|
407
|
47 if (first_process == cast<process_t*>(0))
|
389
|
48 {
|
407
|
49 first_process = p;
|
|
50 last_process = p;
|
389
|
51 }
|
|
52 else
|
|
53 {
|
407
|
54 // Update pointers:
|
|
55 last_process->next = p;
|
|
56 p->prev = last_process;
|
|
57 last_process = p;
|
389
|
58 }
|
283
|
59 }
|
|
60
|
407
|
61 function void kill(process_t* p)
|
283
|
62 {
|
|
63 // clean memory
|
|
64 }
|
|
65
|
300
|
66 function process_t* byId(int id)
|
292
|
67 {
|
|
68 // Perform lookup
|
|
69 return 0;
|
|
70 }
|
283
|
71
|