]> git.corax.cc Git - corax/commitdiff
Use task_switch() to switch tasks in sched_tick(), instead of task_set_current()
authorMatthias Kruk <m@m10k.eu>
Sun, 29 Sep 2019 05:53:38 +0000 (14:53 +0900)
committerMatthias Kruk <m@m10k.eu>
Sun, 29 Sep 2019 05:53:38 +0000 (14:53 +0900)
kernel/core/sched.c

index 497d504f603e124de046be0ece9a7311315bdd2c..8fa6199e233bb55a1ffc488e9fbd24b20c85e0f9 100644 (file)
@@ -1,6 +1,7 @@
 #include <config.h>
 #include <corax/types.h>
 #include <corax/heap.h>
+#include <corax/errno.h>
 #include <debug.h>
 #include <arch.h>
 
@@ -10,7 +11,7 @@ struct task_queue {
 };
 
 /* 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)
 {
@@ -20,13 +21,13 @@ 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;
        }
 
@@ -70,16 +71,37 @@ void sched_tick(void)
 
                /* 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);
+}