summaryrefslogtreecommitdiff
path: root/kernel/sched.c
diff options
context:
space:
mode:
authorDanny Holman <dholman@gymli.org>2025-01-12 01:17:36 -0600
committerDanny Holman <dholman@gymli.org>2025-01-12 01:19:11 -0600
commit95cd78840f0891e60f5ebecc8a8eb4fbaf3c2ebf (patch)
treec8c35347b50477929727fa5be9f5d0f55cbe18fd /kernel/sched.c
parent5e166f3042a8e7b3031aae4da7006f80caa53ecc (diff)
PROJECT RESTRUCTURING
Move the entire kernel into its own directory. Create new directories for system commands, libraries and other required essentials for a complete Unix-like operating system. Signed-off-by: Danny Holman <dholman@gymli.org>
Diffstat (limited to 'kernel/sched.c')
-rw-r--r--kernel/sched.c74
1 files changed, 0 insertions, 74 deletions
diff --git a/kernel/sched.c b/kernel/sched.c
deleted file mode 100644
index b6096da..0000000
--- a/kernel/sched.c
+++ /dev/null
@@ -1,74 +0,0 @@
-#include <kernel/sched.h>
-#include <kernel/kthread.h>
-#include <kernel/panic.h>
-#include <libk/io.h>
-#include <libk/kmalloc.h>
-#include <libk/string.h>
-#include <stddef.h>
-
-static struct kthread *run_queue = NULL;
-static struct kthread *wait_queue = NULL;
-static struct kthread *cur = NULL;
-
-static int scheduler_enabled = 0;
-static struct kmutex scheduler_lock;
-
-void sched_init(void) {
- disable_ints();
- cur = kthread_create(NULL, NULL);
- cur->stack = NULL;
- switch_thread(cur, cur);
- cur->state = THREAD_RUNNING;
- scheduler_enabled = 1;
- enable_ints();
-}
-
-void schedule_next(void) {
- if (scheduler_enabled == 0)
- return;
- if (run_queue == NULL)
- return;
-
- struct kthread *thread = cur;
- schedule_thread(cur);
- cur = run_queue;
- run_queue = run_queue->next;
- cur->next = NULL;
- cur->state = THREAD_RUNNING;
- switch_thread(thread, cur);
-}
-
-void schedule_thread(struct kthread *thread) {
- if (run_queue == NULL) {
- run_queue = thread;
- return;
- }
-
- kmutex_lock(&scheduler_lock);
- struct kthread *temp = run_queue;
- while (temp->next != NULL)
- temp = temp->next;
- temp->next = thread;
- thread->state = THREAD_READY;
- kmutex_unlock(&scheduler_lock);
-}
-
-void block_thread(struct kthread *thread) {
- kmutex_lock(&scheduler_lock);
- thread->next = wait_queue;
- wait_queue = thread;
- kmutex_unlock(&scheduler_lock);
-}
-
-void unblock_thread(struct kthread *thread) {
- kmutex_lock(&scheduler_lock);
- struct kthread *temp = wait_queue;
- while (temp != NULL) {
- if (temp->next == thread) {
- temp->next = thread->next;
- return;
- }
- temp = temp->next;
- }
- kmutex_unlock(&scheduler_lock);
-}