Nucleus
Barry Fixed scheduler double-schedule bug 6063f66 (3 years, 2 months ago)
diff --git a/task/scheduler.c b/task/scheduler.c
index dc7551f..485301e 100644
--- a/task/scheduler.c
+++ b/task/scheduler.c
@@ -6,7 +6,7 @@
* available. This avoids the need for an idle task.
*/
-#include <nucleus/panic.h>
+#include <nucleus/kernel.h>
#include <nucleus/task.h>
#define PRIORITY_COUNT 6
@@ -28,7 +28,11 @@ switch_to_task(Task *task)
}
/* Switch to new context */
+ uintptr_t eip, esp, ebp;
current = task; /* Given reference, so no get() */
+ eip = current->eip;
+ esp = current->esp;
+ ebp = current->ebp;
asm volatile (
"cli;"
"movl %0, %%ecx;"
@@ -37,8 +41,8 @@ switch_to_task(Task *task)
"movl %3, %%cr3;"
"sti;"
"jmp *%%ecx"
- :: "g" (current->eip), "g" (current->esp),
- "g" (current->ebp), "g" (current->pageDir)
+ :: "g" (eip), "g" (esp),
+ "g" (ebp), "g" (current->pageDir)
);
end:
/* This prevents GCC from optimising the jump to be after the return */
@@ -82,6 +86,8 @@ schedule(void)
/* Schedule next task */
task = pop_from_start(queue);
task->state = RUNNING;
+ if (task == current)
+ return;
if (current && current->state == RUNNING) {
current->state = READY;
add(readyQueue[current->priority], current);