Mercurial > lcfOS
comparison kernel/process.c3 @ 402:0fb6633c42f6
Moved several files to logical locations
author | Windel Bouwman |
---|---|
date | Thu, 19 Feb 2015 00:13:07 +0100 |
parents | kernel/src/process.c3@6ae782a085e0 |
children | 9eb1fc6aad6c |
comparison
equal
deleted
inserted
replaced
401:994c00d55fd5 | 402:0fb6633c42f6 |
---|---|
1 module process; | |
2 | |
3 import memory; | |
4 import kernel; | |
5 | |
6 // process type definition: | |
7 type struct { | |
8 int id; | |
9 int status; | |
10 process_t* next; // For linked list.. | |
11 } process_t; | |
12 | |
13 // Or, use this list structure: | |
14 // List<process_t> procs; | |
15 | |
16 // init is the root of all processes: | |
17 var process_t* root_process; | |
18 | |
19 var int next_pid; | |
20 | |
21 function void init() | |
22 { | |
23 next_pid = 0; | |
24 root_process = create(); | |
25 } | |
26 | |
27 /* | |
28 Create a new process. | |
29 */ | |
30 function process_t* create() | |
31 { | |
32 var process_t* p; | |
33 | |
34 p = cast<process_t*>(memory.alloc(sizeof(process_t))); | |
35 p->id = next_pid; | |
36 p->status = 0; // Ready! | |
37 p->next = cast<process_t*>(0); | |
38 | |
39 // Increment PID: | |
40 next_pid = next_pid + 1; | |
41 | |
42 // Store it in the list: | |
43 if (root_process == cast<process_t*>(0)) | |
44 { | |
45 root_process = p; | |
46 } | |
47 else | |
48 { | |
49 var process_t* parent; | |
50 parent = root_process; | |
51 while (parent->next != cast<process_t*>(0)) | |
52 { | |
53 parent = parent->next; | |
54 } | |
55 | |
56 parent->next = p; | |
57 } | |
58 | |
59 return p; | |
60 } | |
61 | |
62 | |
63 function void Kill(process_t* p) | |
64 { | |
65 // clean memory | |
66 } | |
67 | |
68 function process_t* byId(int id) | |
69 { | |
70 // Perform lookup | |
71 return 0; | |
72 } | |
73 |