From: Matthias Kruk Date: Sat, 21 Mar 2020 17:45:19 +0000 (+0900) Subject: sched/lazy: Make sure _lazy_tick() doesn't break if ctask is NULL, which happens... X-Git-Url: https://git.corax.cc/?a=commitdiff_plain;h=b4435716e23d3c5844e3015a0069dd87706b5123;p=corax sched/lazy: Make sure _lazy_tick() doesn't break if ctask is NULL, which happens the first time it is called --- diff --git a/kernel/sched/lazy.c b/kernel/sched/lazy.c index 88f76c0..eed9823 100644 --- a/kernel/sched/lazy.c +++ b/kernel/sched/lazy.c @@ -27,38 +27,44 @@ static int _lazy_tick(struct sched_lazy *lazy) ctask = task_get_current(); ret_val = 0; - task_lock(ctask); + if(ctask) { + task_lock(ctask); - if(ctask->t_state != TASK_STATE_EXIT) { - if(ctask->t_rslice) { - ctask->t_rslice--; - } else { - /* task has exhausted its time slice - reschedule */ - ctask->t_rslice = ctask->t_tslice; - ctask->t_state = TASK_STATE_READY; - ret_val = 1; + if(ctask->t_state != TASK_STATE_EXIT) { + if(ctask->t_rslice) { + ctask->t_rslice--; + } else { + /* task has exhausted its time slice - reschedule */ + ctask->t_rslice = ctask->t_tslice; + ctask->t_state = TASK_STATE_READY; + ret_val = 1; + } } - } - task_unlock(ctask); + task_unlock(ctask); + } else { + ret_val = 1; + } if(ret_val) { /* rescheduling is required */ _LOCK(lazy); - /* put current task back on the ready queue */ - ret_val = kq_nq(&(lazy->readyq), ctask); - - if(ret_val < 0) { - /* - * FIXME: could not put task back on ready queue - wat do? - * - * If we don't do anything here, the task would be silently - * dropped by the scheduler and never get scheduled again. - * Instead, it would be better if we could move it to a different - * processor, which (on NUMA systems) might have enough memory - * available to schedule the task. - */ + if(ctask) { + /* put current task back on the ready queue */ + ret_val = kq_nq(&(lazy->readyq), ctask); + + if(ret_val < 0) { + /* + * FIXME: could not put task back on ready queue - wat do? + * + * If we don't do anything here, the task would be silently + * dropped by the scheduler and never get scheduled again. + * Instead, it would be better if we could move it to a different + * processor, which (on NUMA systems) might have enough memory + * available to schedule the task. + */ + } } /* get the first ready task */