From 02a12be131abbf74f3df90b0673e363c9d35b1c1 Mon Sep 17 00:00:00 2001 From: Matthias Kruk Date: Sun, 29 Sep 2019 14:53:38 +0900 Subject: [PATCH] Use task_switch() to switch tasks in sched_tick(), instead of task_set_current() --- kernel/core/sched.c | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/kernel/core/sched.c b/kernel/core/sched.c index 497d504..8fa6199 100644 --- a/kernel/core/sched.c +++ b/kernel/core/sched.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -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); +} -- 2.47.3