annotate kernel/process.c3 @ 407:9eb1fc6aad6c

Minor improvements
author Windel Bouwman
date Fri, 20 Feb 2015 15:47:54 +0100
parents 0fb6633c42f6
children ad6be5454067
rev   line source
283
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
1 module process;
300
Windel Bouwman
parents: 296
diff changeset
2
283
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
3 import memory;
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
4 import kernel;
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
5
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
6 // process type definition:
296
9417caea2eb3 Directorized some backend files
Windel Bouwman
parents: 295
diff changeset
7 type struct {
283
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
8 int id;
292
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 283
diff changeset
9 int status;
407
9eb1fc6aad6c Minor improvements
Windel Bouwman
parents: 402
diff changeset
10 process_t* next;
9eb1fc6aad6c Minor improvements
Windel Bouwman
parents: 402
diff changeset
11 process_t* prev;
283
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
12 } process_t;
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
13
407
9eb1fc6aad6c Minor improvements
Windel Bouwman
parents: 402
diff changeset
14 var process_t* first_process;
9eb1fc6aad6c Minor improvements
Windel Bouwman
parents: 402
diff changeset
15 var process_t* last_process;
306
b145f8e6050b Start on c3 rewrite
Windel Bouwman
parents: 301
diff changeset
16 var int next_pid;
283
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
17
296
9417caea2eb3 Directorized some backend files
Windel Bouwman
parents: 295
diff changeset
18 function void init()
283
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
19 {
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
20 next_pid = 0;
407
9eb1fc6aad6c Minor improvements
Windel Bouwman
parents: 402
diff changeset
21 first_process = 0;
9eb1fc6aad6c Minor improvements
Windel Bouwman
parents: 402
diff changeset
22 last_process = 0;
283
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
23 }
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
24
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
25 /*
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
26 Create a new process.
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
27 */
402
0fb6633c42f6 Moved several files to logical locations
Windel Bouwman
parents: 393
diff changeset
28 function process_t* create()
283
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
29 {
301
6753763d3bec merge codegen into ppci package
Windel Bouwman
parents: 300
diff changeset
30 var process_t* p;
389
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 359
diff changeset
31
407
9eb1fc6aad6c Minor improvements
Windel Bouwman
parents: 402
diff changeset
32 p = memory.alloc(sizeof(process_t));
283
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
33 p->id = next_pid;
393
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
34 p->status = 0; // Ready!
407
9eb1fc6aad6c Minor improvements
Windel Bouwman
parents: 402
diff changeset
35 p->next = 0;
9eb1fc6aad6c Minor improvements
Windel Bouwman
parents: 402
diff changeset
36 p->prev = 0;
389
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 359
diff changeset
37
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 359
diff changeset
38 // Increment PID:
300
Windel Bouwman
parents: 296
diff changeset
39 next_pid = next_pid + 1;
389
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 359
diff changeset
40
407
9eb1fc6aad6c Minor improvements
Windel Bouwman
parents: 402
diff changeset
41 return p;
9eb1fc6aad6c Minor improvements
Windel Bouwman
parents: 402
diff changeset
42 }
9eb1fc6aad6c Minor improvements
Windel Bouwman
parents: 402
diff changeset
43
9eb1fc6aad6c Minor improvements
Windel Bouwman
parents: 402
diff changeset
44 function void enqueue(process_t* p)
9eb1fc6aad6c Minor improvements
Windel Bouwman
parents: 402
diff changeset
45 {
389
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 359
diff changeset
46 // Store it in the list:
407
9eb1fc6aad6c Minor improvements
Windel Bouwman
parents: 402
diff changeset
47 if (first_process == cast<process_t*>(0))
389
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 359
diff changeset
48 {
407
9eb1fc6aad6c Minor improvements
Windel Bouwman
parents: 402
diff changeset
49 first_process = p;
9eb1fc6aad6c Minor improvements
Windel Bouwman
parents: 402
diff changeset
50 last_process = p;
389
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 359
diff changeset
51 }
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 359
diff changeset
52 else
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 359
diff changeset
53 {
407
9eb1fc6aad6c Minor improvements
Windel Bouwman
parents: 402
diff changeset
54 // Update pointers:
9eb1fc6aad6c Minor improvements
Windel Bouwman
parents: 402
diff changeset
55 last_process->next = p;
9eb1fc6aad6c Minor improvements
Windel Bouwman
parents: 402
diff changeset
56 p->prev = last_process;
9eb1fc6aad6c Minor improvements
Windel Bouwman
parents: 402
diff changeset
57 last_process = p;
389
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 359
diff changeset
58 }
283
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
59 }
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
60
407
9eb1fc6aad6c Minor improvements
Windel Bouwman
parents: 402
diff changeset
61 function void kill(process_t* p)
283
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
62 {
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
63 // clean memory
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
64 }
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
65
300
Windel Bouwman
parents: 296
diff changeset
66 function process_t* byId(int id)
292
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 283
diff changeset
67 {
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 283
diff changeset
68 // Perform lookup
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 283
diff changeset
69 return 0;
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 283
diff changeset
70 }
283
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
71