Skip to content

Commit ab4bcb5

Browse files
committed
Add sched_migrate_task() helper
This commit introduces a new helper, sched_migrate_task(), which migrates a task between ready queues of different priority levels and will be introduced in mo_task_priority() for readability.
1 parent 261b4e4 commit ab4bcb5

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

kernel/task.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,27 @@ void sched_dequeue_task(tcb_t *task)
432432
return;
433433
}
434434

435+
/* Task migration from origin to new priority ready queue */
436+
static void sched_migrate_task(tcb_t *task, int16_t priority)
437+
{
438+
if (unlikely(!task || !is_valid_priority(priority)))
439+
return;
440+
441+
if (task->prio == priority)
442+
return;
443+
444+
/* Remove task node from origin ready queue */
445+
sched_dequeue_task(task);
446+
447+
/* Update new properties */
448+
task->prio = priority;
449+
task->prio_level = extract_priority_level(priority);
450+
451+
/* Enqueue task node into new priority ready queue*/
452+
sched_enqueue_task(task);
453+
return;
454+
}
455+
435456
/* Handle time slice expiration for current task */
436457
void sched_tick_current_task(void)
437458
{

0 commit comments

Comments
 (0)