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 */