BarryServer : Git

All the code for all my projects
// BarryServer : Git / Nucleus / commit / c530261a6ef76632384504044bc0b0519a33938e / task / clone.c

// Related

Nucleus

Barry Task queues and full scheduling c530261 (3 years, 3 months ago)
diff --git a/task/clone.c b/task/clone.c
index 0c95083..f7496c9 100644
--- a/task/clone.c
+++ b/task/clone.c
@@ -6,6 +6,8 @@
 #include <sys/types.h>
 #include <nucleus/task.h>
 
+extern TaskQueue *readyQueue[];
+
 /* Read the EIP */
 static uintptr_t
 read_eip(void)
@@ -20,22 +22,23 @@ pid_t
 clone(int flags)
 {
 	Task *parent = current, *child = new(&taskType), *tmp;
+	pid_t tid = 0;
 
+	/* After this, anything on the stack is desynchronised */
 	child->pageDir = clone_dir();
 
-	parent->next = child;
-	child->next = parent;
-
 	/* Split tasks here */
 	uintptr_t esp, ebp, eip;
-	eip = read_eip();
-	if (current == parent) {
-		asm volatile("mov %%esp, %0" : "=r" (esp));
-		asm volatile("mov %%ebp, %0" : "=r" (ebp));
-		child->esp = esp;
-		child->ebp = ebp;
-		child->eip = eip;
-		return child->tid;
-	}
-	return 0;
+	eip = (uintptr_t) &&end;
+
+	asm volatile("mov %%esp, %0" : "=r" (esp));
+	asm volatile("mov %%ebp, %0" : "=r" (ebp));
+	child->esp = esp;
+	child->ebp = ebp;
+	child->eip = eip;
+	add_to_queue(readyQueue[child->priority], child);
+	tid = child->tid;
+	put(child);
+end:
+	return tid;
 }