annotate 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
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;
389
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 359
diff changeset
10 process_t* next; // For linked list..
283
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
11 } process_t;
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
12
292
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 283
diff changeset
13 // Or, use this list structure:
296
9417caea2eb3 Directorized some backend files
Windel Bouwman
parents: 295
diff changeset
14 // List<process_t> procs;
292
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 283
diff changeset
15
283
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
16 // init is the root of all processes:
389
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 359
diff changeset
17 var process_t* root_process;
393
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
18
306
b145f8e6050b Start on c3 rewrite
Windel Bouwman
parents: 301
diff changeset
19 var int next_pid;
283
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
20
296
9417caea2eb3 Directorized some backend files
Windel Bouwman
parents: 295
diff changeset
21 function void init()
283
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
22 {
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
23 next_pid = 0;
402
0fb6633c42f6 Moved several files to logical locations
Windel Bouwman
parents: 393
diff changeset
24 root_process = create();
283
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
25 }
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
26
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
27 /*
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
28 Create a new process.
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
29 */
402
0fb6633c42f6 Moved several files to logical locations
Windel Bouwman
parents: 393
diff changeset
30 function process_t* create()
283
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
31 {
301
6753763d3bec merge codegen into ppci package
Windel Bouwman
parents: 300
diff changeset
32 var process_t* p;
389
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 359
diff changeset
33
393
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
34 p = cast<process_t*>(memory.alloc(sizeof(process_t)));
283
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
35 p->id = next_pid;
393
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
36 p->status = 0; // Ready!
389
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 359
diff changeset
37 p->next = cast<process_t*>(0);
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 359
diff changeset
38
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 359
diff changeset
39 // Increment PID:
300
Windel Bouwman
parents: 296
diff changeset
40 next_pid = next_pid + 1;
389
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 359
diff changeset
41
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 359
diff changeset
42 // Store it in the list:
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 359
diff changeset
43 if (root_process == cast<process_t*>(0))
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 359
diff changeset
44 {
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 359
diff changeset
45 root_process = p;
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 359
diff changeset
46 }
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 359
diff changeset
47 else
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 359
diff changeset
48 {
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 359
diff changeset
49 var process_t* parent;
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 359
diff changeset
50 parent = root_process;
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 359
diff changeset
51 while (parent->next != cast<process_t*>(0))
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 359
diff changeset
52 {
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 359
diff changeset
53 parent = parent->next;
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 359
diff changeset
54 }
393
6ae782a085e0 Added init program
Windel Bouwman
parents: 389
diff changeset
55
389
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 359
diff changeset
56 parent->next = p;
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 359
diff changeset
57 }
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 return p;
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
60 }
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
61
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
62
300
Windel Bouwman
parents: 296
diff changeset
63 function void Kill(process_t* p)
283
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
64 {
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
65 // clean memory
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
66 }
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
67
300
Windel Bouwman
parents: 296
diff changeset
68 function process_t* byId(int id)
292
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 283
diff changeset
69 {
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 283
diff changeset
70 // Perform lookup
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 283
diff changeset
71 return 0;
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 283
diff changeset
72 }
283
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
73