Skip to content

Commit fbfdfde

Browse files
committed
Refactor dequeuing logic for the new scheduler
This commit refactors mo_dequeue_task() to support data structures for the new scheduler. - Set the RR cursor to NULL when no task remains in the ready queue - Circularly advance the RR cursor if it currently points to the task being dequeued, avoid RR cursor points to unlinked node.
1 parent ddd1205 commit fbfdfde

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

kernel/task.c

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -404,16 +404,32 @@ static void sched_enqueue_task(tcb_t *task)
404404
return;
405405
}
406406

407-
/* Remove task from ready queues - state-based approach for compatibility */
407+
/* Remove task from ready queue */
408408
void sched_dequeue_task(tcb_t *task)
409409
{
410410
if (unlikely(!task))
411411
return;
412412

413-
/* For tasks that need to be removed from ready state (suspended/cancelled),
414-
* we rely on the state change. The scheduler will skip non-ready tasks
415-
* when it encounters them during the round-robin traversal.
416-
*/
413+
uint8_t prio_level = task->prio_level;
414+
415+
/* For task that need to be removed from ready/running state, it need be
416+
* removed from corresponding ready queue. */
417+
list_t *rq = kcb->ready_queues[prio_level];
418+
list_node_t **cursor = &kcb->rr_cursors[prio_level];
419+
420+
/* Safely move cursor to next task node. */
421+
if (&task->rq_node == *cursor)
422+
*cursor = list_cnext(rq, *cursor);
423+
424+
/* Remove ready queue node */
425+
list_remove_node(rq, &task->rq_node);
426+
427+
/* Update task count in ready queue */
428+
if (!--kcb->queue_counts[prio_level]) {
429+
*cursor = NULL;
430+
bitmap_clean(task->prio_level);
431+
}
432+
return;
417433
}
418434

419435
/* Handle time slice expiration for current task */

0 commit comments

Comments
 (0)