diff kernel/src/process.c3 @ 389:2ec730e45ea1

Added check for recursive struct
author Windel Bouwman
date Fri, 16 May 2014 12:29:31 +0200
parents b4ac28efcdf4
children 6ae782a085e0
line wrap: on
line diff
--- a/kernel/src/process.c3	Fri May 02 14:51:46 2014 +0200
+++ b/kernel/src/process.c3	Fri May 16 12:29:31 2014 +0200
@@ -7,19 +7,21 @@
 type struct {
     int id;
     int status;
+    process_t* next; // For linked list..
 } process_t;
 
 // Or, use this list structure:
 // List<process_t> procs;
 
 // init is the root of all processes:
-var process_t* init_pid;
+var process_t* root_process;
 var int next_pid;
 
 function void init()
 {
     next_pid = 0;
-    init_pid = Create();
+    root_process = cast<process_t*>(0);
+    // init_pid = Create();
 }
 
 /*
@@ -28,12 +30,36 @@
 function process_t* Create()
 {
     var process_t* p;
+    //TODO: implement alloc:
+
     //= memory.Alloc(sizeof(process_t));
     p->id = next_pid;
+    p->next = cast<process_t*>(0);
+
+    // Increment PID:
     next_pid = next_pid + 1;
+
+    // Store it in the list:
+    if (root_process == cast<process_t*>(0))
+    {
+        root_process = p;
+    }
+    else
+    {
+        var process_t* parent;
+        parent = root_process;
+        while (parent->next != cast<process_t*>(0))
+        {
+            parent = parent->next;
+        }
+        parent->next = p;
+    }
+
     return p;
 }
 
+// function
+
 
 function void Kill(process_t* p)
 {