]> git.corax.cc Git - corax/commitdiff
sched/lazy: Make sure _lazy_tick() doesn't break if ctask is NULL, which happens...
authorMatthias Kruk <m@m10k.eu>
Sat, 21 Mar 2020 17:45:19 +0000 (02:45 +0900)
committerMatthias Kruk <m@m10k.eu>
Sat, 21 Mar 2020 17:45:19 +0000 (02:45 +0900)
kernel/sched/lazy.c

index 88f76c04fd276939eb751378193ad9843e17825e..eed982315a7170dab26fabfb11c775cc57567dbf 100644 (file)
@@ -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 */