aboutsummaryrefslogtreecommitdiff
path: root/kernel/task/include/task/sched.h
diff options
context:
space:
mode:
authorJakob Odersky <jodersky@gmail.com>2014-03-17 15:53:45 +0100
committerJakob Odersky <jodersky@gmail.com>2014-03-17 15:53:45 +0100
commit5466218a5f9fb3d46f608806f222fcc99a306a4b (patch)
tree2d82056fe24bc508a985881149595fd83760b72a /kernel/task/include/task/sched.h
parentd106637504ec4cb5fa63feab11bd845faea2bc07 (diff)
downloadmux-5466218a5f9fb3d46f608806f222fcc99a306a4b.tar.gz
mux-5466218a5f9fb3d46f608806f222fcc99a306a4b.tar.bz2
mux-5466218a5f9fb3d46f608806f222fcc99a306a4b.zip
no time scheduler
Diffstat (limited to 'kernel/task/include/task/sched.h')
-rw-r--r--kernel/task/include/task/sched.h63
1 files changed, 63 insertions, 0 deletions
diff --git a/kernel/task/include/task/sched.h b/kernel/task/include/task/sched.h
new file mode 100644
index 0000000..9029664
--- /dev/null
+++ b/kernel/task/include/task/sched.h
@@ -0,0 +1,63 @@
+#ifndef SCHED_H
+#define SCHED_H
+
+#include "collection/list.h"
+#include "mcu/task/task.h"
+
+/**
+ * Points to currently executing task. If no scheduling has been enabled,
+ * this points to NULL
+ */
+extern struct tcb_t* volatile current;
+
+/**
+ * Queue that contains all tasks that are ready to be run, awaiting their
+ * turn from the scheduler.
+ */
+extern struct list_head ready;
+
+/**
+ * Stack pointer for operations performed out of task context, including any
+ * calls made after SAVE_CONTEXT().
+ */
+extern void* volatile kstack;
+
+/**
+ * Makes the current task sleep on a specific queue.
+ * This moves the current task to the given queue's tail.
+ */
+static inline void sleep_queue(struct list_head* queue) {
+ list_move_tail(&current->queue, queue);
+}
+
+/**
+ * Wakes all tasks waiting in the given queue.
+ * This moves all tasks contained in the queue to the ready queue.
+ */
+static inline void wake_all_queue(struct list_head* queue) {
+ list_splice_init(queue, ready.prev);
+}
+
+/**
+ * Initializes a given task and adds it to the ready queue.
+ */
+void spawn(struct tcb_t* const tcb);
+
+/**
+ * Voluntarily relinquishes control of the CPU from the current task to the scheduler.
+ */
+void yield() __attribute__ ( ( naked ) );
+
+
+/**
+ * Initializes the scheduler by setting up kstack, initializing the idle task
+ * and selecting the first task to run.
+ */
+void sched_init();
+
+/**
+ * Enters the scheduler, setting current to the next runnable task.
+ */
+void schedule();
+
+#endif