summaryrefslogtreecommitdiff
path: root/kernel/src/scheduler/scheduler.c
diff options
context:
space:
mode:
authorAleksa Vuckovic <aleksa@vuckovic.cc>2023-02-27 01:59:33 +0100
committerAleksa Vuckovic <aleksa@vuckovic.cc>2023-02-27 01:59:33 +0100
commit15f3911599a8d005edee46247470afe2a7a0b4aa (patch)
tree3113b84e1ddddc1f4937ca5596d8e32aacc4f51f /kernel/src/scheduler/scheduler.c
parenta164ca67174ba6179170dea573479f23122513cc (diff)
almost done multitasking
Diffstat (limited to 'kernel/src/scheduler/scheduler.c')
-rw-r--r--kernel/src/scheduler/scheduler.c29
1 files changed, 28 insertions, 1 deletions
diff --git a/kernel/src/scheduler/scheduler.c b/kernel/src/scheduler/scheduler.c
index 263c11a..3cbc461 100644
--- a/kernel/src/scheduler/scheduler.c
+++ b/kernel/src/scheduler/scheduler.c
@@ -2,11 +2,38 @@
#include <scheduler.h>
#include <libk/list.h>
#include <process.h>
+#include <heap.h>
+#include <libk/string.h>
+#include <libk/stdio.h>
+#include <panic.h>
-process_t *scheduler(void)
+mutex_t scheduler_lock;
+uint32_t sched_init = 0;
+
+__attribute__((noreturn)) void init_scheduler()
+{
+ INIT_LIST(process_queue.list);
+ init_mutex(&scheduler_lock);
+ uint64_t argc = 6;
+ uint64_t *argv = (uint64_t *)kalloc(sizeof(uint64_t) * 6);
+ memset(argv, 0, sizeof(uint64_t) * 6);
+ init_process(0, (uint64_t)idle_thread2, argc, argv);
+ curr_process = init_process(0, (uint64_t)idle_thread, argc, argv);
+ sched_init = 1;
+ restore_context_from_rsp(curr_process->rsp);
+}
+
+process_t *scheduler()
{
+ lock(scheduler_lock);
process_t *pos = curr_process;
+ if (list_is_empty((&process_queue.list)))
+ return NULL;
process_t *next_process = list_next_entry(pos, list);
+ while (next_process->rsp == 0) {
+ next_process = list_next_entry(next_process, list);
+ }
+ unlock(scheduler_lock);
return next_process;
}