#include <config.h>
#include <corax/types.h>
#include <corax/heap.h>
+#include <corax/errno.h>
#include <debug.h>
#include <arch.h>
};
/* FIXME: This should be per-processor */
-static struct task_queue *_readyq;
+static struct task_queue *_readyq = NULL;
static void _nq(struct task_queue **q, task_t *t)
{
if(item) {
item->data = t;
+ item->next = NULL;
/* get a pointer to the end of the queue */
while(*q) {
- q = &((*q)->next);
+ q = &((*q)->next);
}
- item->next = *q;
*q = item;
}
/* put the task back on the ready queue */
_nq(&_readyq, cur_task);
+ }
- /* get the next task from the ready queue */
- cur_task = _dq(&_readyq);
+ /* get the next task from the ready queue */
+ cur_task = _dq(&_readyq);
- if(cur_task) {
- task_set_current(cur_task);
- } else {
- dbg_printf("This should not have happened\n");
- }
+ if(cur_task) {
+ dbg_printf("Switch to task %p [%02x]\n", cur_task, cur_task->t_state);
+ task_switch(cur_task);
+ dbg_printf("Returned to task %p\n", task_get_current());
+ } else {
+ dbg_printf("This should not have happened\n");
}
return;
}
+
+int sched_enqueue(task_t *t)
+{
+ int ret_val;
+
+ ret_val = -EINVAL;
+
+ /*
+ * Don't allow tasks to be enqueued unless they are in
+ * state TASK_STATE_NEW
+ */
+
+ if(t->t_state == TASK_STATE_NEW) {
+ _nq(&_readyq, t);
+ ret_val = 0;
+ }
+
+ return(ret_val);
+}