aboutsummaryrefslogtreecommitdiff
path: root/kernel/include/proc/sched.h
diff options
context:
space:
mode:
authornthnluu <nate1299@me.com>2024-01-28 21:20:27 -0500
committernthnluu <nate1299@me.com>2024-01-28 21:20:27 -0500
commitc63f340d90800895f007de64b7d2d14624263331 (patch)
tree2c0849fa597dd6da831c8707b6f2603403778d7b /kernel/include/proc/sched.h
Created student weenix repository
Diffstat (limited to 'kernel/include/proc/sched.h')
-rw-r--r--kernel/include/proc/sched.h126
1 files changed, 126 insertions, 0 deletions
diff --git a/kernel/include/proc/sched.h b/kernel/include/proc/sched.h
new file mode 100644
index 0000000..343e8d5
--- /dev/null
+++ b/kernel/include/proc/sched.h
@@ -0,0 +1,126 @@
+#pragma once
+
+#include "proc/spinlock.h"
+#include "util/list.h"
+
+/*===========
+ * Structures
+ *==========*/
+
+/*
+ * Queue structure for kthreads
+ * Note that ktqueue functions are private - managing the queue
+ * should be done within sched.c, or using public functions
+ */
+typedef struct ktqueue
+{
+ list_t tq_list;
+ size_t tq_size;
+} ktqueue_t;
+
+/*
+ * Macro to initialize a ktqueue. See sched_queue_init for how the
+ * queue should be initialized in your code.
+ */
+#define KTQUEUE_INITIALIZER(ktqueue) \
+ { \
+ .tq_list = LIST_INITIALIZER((ktqueue).tq_list), \
+ }
+
+/*
+ * kthread declaration to make function signatures happy
+ */
+struct kthread;
+
+/*==========
+ * Functions
+ *=========*/
+
+/**
+ * Runs a new thread from the run queue.
+ *
+ * @param queue the queue to place curthr on
+ */
+void sched_switch(ktqueue_t *queue);
+
+/**
+ * Helps with context switching.
+ */
+void core_switch();
+
+/**
+ * Yields the CPU to another runnable thread.
+ */
+void sched_yield();
+
+/**
+ * Enables a thread to be selected by the scheduler to run.
+ *
+ * @param thr the thread to make runnable
+ */
+void sched_make_runnable(struct kthread *thr);
+
+/**
+ * Causes the current thread to enter into an uncancellable sleep on
+ * the given queue.
+ *
+ * @param q the queue to sleep on
+ * @param lock optional lock for release in another context
+ */
+void sched_sleep_on(ktqueue_t *q);
+
+/**
+ * Causes the current thread to enter into a cancellable sleep on the
+ * given queue.
+ *
+ * @param queue the queue to sleep on
+ * @param lock optional lock for release in another context
+ * @return -EINTR if the thread was cancelled and 0 otherwise
+ */
+long sched_cancellable_sleep_on(ktqueue_t *queue);
+
+/**
+ * Wakes up a thread from q.
+ *
+ * @param q queue
+ * @param thrp if an address is provided, *thrp is set to the woken up thread
+ *
+ */
+void sched_wakeup_on(ktqueue_t *q, struct kthread **thrp);
+
+/**
+ * Wake up all threads running on the queue.
+ *
+ * @param q the queue to wake up threads from
+ */
+void sched_broadcast_on(ktqueue_t *q);
+
+/**
+ * Cancel the given thread from the queue it sleeps on.
+ *
+ * @param the thread to cancel sleep from
+ */
+void sched_cancel(struct kthread *thr);
+
+/**
+ * Initializes a queue.
+ *
+ * @param queue the queue
+ */
+void sched_queue_init(ktqueue_t *queue);
+
+/**
+ * Returns true if the queue is empty.
+ *
+ * @param queue the queue
+ * @return true if the queue is empty
+ */
+long sched_queue_empty(ktqueue_t *queue);
+
+/**
+ * Functions for managing the current thread's preemption status.
+ */
+void preemption_disable();
+void preemption_enable();
+void preemption_reset();
+long preemption_enabled(); \ No newline at end of file