Skip to content

Commit 2f527ab

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 b2ebd49 commit 2f527ab

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
@@ -382,16 +382,32 @@ static void sched_enqueue_task(tcb_t *task)
382382
return;
383383
}
384384

385-
/* Remove task from ready queues - state-based approach for compatibility */
385+
/* Remove task from ready queue */
386386
void sched_dequeue_task(tcb_t *task)
387387
{
388388
if (unlikely(!task))
389389
return;
390390

391-
/* For tasks that need to be removed from ready state (suspended/cancelled),
392-
* we rely on the state change. The scheduler will skip non-ready tasks
393-
* when it encounters them during the round-robin traversal.
394-
*/
391+
uint8_t prio_level = task->prio_level;
392+
393+
/* For task that need to be removed from ready/running state, it need be
394+
* removed from corresponding ready queue. */
395+
list_t *rq = kcb->ready_queues[prio_level];
396+
list_node_t **cursor = &kcb->rr_cursors[prio_level];
397+
398+
/* Safely move cursor to next task node. */
399+
if (&task->rq_node == *cursor)
400+
*cursor = list_cnext(rq, *cursor);
401+
402+
/* Remove ready queue node */
403+
list_remove_node(rq, &task->rq_node);
404+
405+
/* Update task count in ready queue */
406+
if (!--kcb->queue_counts[prio_level]) {
407+
*cursor = NULL;
408+
bitmap_clean(task->prio_level);
409+
}
410+
return;
395411
}
396412

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

0 commit comments

Comments
 (0)