From 7b03940676f9111caff836c3b2da13d40d305af8 Mon Sep 17 00:00:00 2001 From: Matthias Kruk Date: Fri, 1 May 2020 10:39:36 +0900 Subject: [PATCH] sched/lazy: Fix bug in _lazy_tick() causing waiting processes to be scheduled --- kernel/sched/lazy.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/kernel/sched/lazy.c b/kernel/sched/lazy.c index eed9823..fb7c7be 100644 --- a/kernel/sched/lazy.c +++ b/kernel/sched/lazy.c @@ -36,7 +36,16 @@ static int _lazy_tick(struct sched_lazy *lazy) } else { /* task has exhausted its time slice - reschedule */ ctask->t_rslice = ctask->t_tslice; - ctask->t_state = TASK_STATE_READY; + + /* + * This function will also be called with the intention to + * reschedule, for example because the current task has changed + * to TASK_STATE_WAITING. In such a case, we should not override + * the task state here. + */ + if(ctask->t_state == TASK_STATE_RUNNING) { + ctask->t_state = TASK_STATE_READY; + } ret_val = 1; } } -- 2.47.3