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;
|
408
|
17 var process_t* current;
|
283
|
18
|
296
|
19 function void init()
|
283
|
20 {
|
|
21 next_pid = 0;
|
407
|
22 first_process = 0;
|
|
23 last_process = 0;
|
283
|
24 }
|
|
25
|
|
26 /*
|
|
27 Create a new process.
|
|
28 */
|
402
|
29 function process_t* create()
|
283
|
30 {
|
301
|
31 var process_t* p;
|
389
|
32
|
407
|
33 p = memory.alloc(sizeof(process_t));
|
283
|
34 p->id = next_pid;
|
393
|
35 p->status = 0; // Ready!
|
407
|
36 p->next = 0;
|
|
37 p->prev = 0;
|
389
|
38
|
|
39 // Increment PID:
|
300
|
40 next_pid = next_pid + 1;
|
389
|
41
|
407
|
42 return p;
|
|
43 }
|
|
44
|
|
45 function void enqueue(process_t* p)
|
|
46 {
|
389
|
47 // Store it in the list:
|
407
|
48 if (first_process == cast<process_t*>(0))
|
389
|
49 {
|
407
|
50 first_process = p;
|
|
51 last_process = p;
|
389
|
52 }
|
|
53 else
|
|
54 {
|
407
|
55 // Update pointers:
|
|
56 last_process->next = p;
|
|
57 p->prev = last_process;
|
|
58 last_process = p;
|
389
|
59 }
|
283
|
60 }
|
|
61
|
407
|
62 function void kill(process_t* p)
|
283
|
63 {
|
|
64 // clean memory
|
|
65 }
|
|
66
|
300
|
67 function process_t* byId(int id)
|
292
|
68 {
|
|
69 // Perform lookup
|
|
70 return 0;
|
|
71 }
|
283
|
72
|
408
|
73
|
|
74 function void execute_next()
|
|
75 {
|
|
76 var process.process_t *old;
|
|
77
|
|
78 old = 0;
|
|
79
|
|
80 if (old != current)
|
|
81 {
|
|
82 //execute(current);
|
|
83 }
|
|
84
|
|
85 kernel.panic();
|
|
86 }
|