} 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;
}
}