diff kernel/process.c3 @ 407:9eb1fc6aad6c

Minor improvements
author Windel Bouwman
date Fri, 20 Feb 2015 15:47:54 +0100
parents 0fb6633c42f6
children ad6be5454067
line wrap: on
line diff
--- a/kernel/process.c3	Fri Feb 20 14:25:35 2015 +0100
+++ b/kernel/process.c3	Fri Feb 20 15:47:54 2015 +0100
@@ -7,21 +7,19 @@
 type struct {
     int id;
     int status;
-    process_t* next; // For linked list..
+    process_t* next;
+    process_t* prev;
 } process_t;
 
-// Or, use this list structure:
-// List<process_t> procs;
-
-// init is the root of all processes:
-var process_t* root_process;
-
+var process_t* first_process;
+var process_t* last_process;
 var int next_pid;
 
 function void init()
 {
     next_pid = 0;
-    root_process = create();
+    first_process = 0;
+    last_process = 0;
 }
 
 /*
@@ -31,36 +29,36 @@
 {
     var process_t* p;
 
-    p = cast<process_t*>(memory.alloc(sizeof(process_t)));
+    p = memory.alloc(sizeof(process_t));
     p->id = next_pid;
     p->status = 0; // Ready!
-    p->next = cast<process_t*>(0);
+    p->next = 0;
+    p->prev = 0;
 
     // Increment PID:
     next_pid = next_pid + 1;
 
+    return p;
+}
+
+function void enqueue(process_t* p)
+{
     // Store it in the list:
-    if (root_process == cast<process_t*>(0))
+    if (first_process == cast<process_t*>(0))
     {
-        root_process = p;
+        first_process = p;
+        last_process = p;
     }
     else
     {
-        var process_t* parent;
-        parent = root_process;
-        while (parent->next != cast<process_t*>(0))
-        {
-            parent = parent->next;
-        }
-
-        parent->next = p;
+        // Update pointers:
+        last_process->next = p;
+        p->prev = last_process;
+        last_process = p;
     }
-
-    return p;
 }
 
-
-function void Kill(process_t* p)
+function void kill(process_t* p)
 {
     // clean memory
 }