Skip to content

Commit 953e3c7

Browse files
committed
Refactor priority-change path in mo_task_priority()
Previously, mo_task_priority() only updated the task’s time slice and priority level. With the new scheduler design, tasks are kept in per-priority ready queues, so mo_task_priority() must also handle migrating tasks between these queues. This change supports task migration from original ready queue to the new priority ready queue.
1 parent e92dda4 commit 953e3c7

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

kernel/task.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,12 +996,30 @@ int32_t mo_task_priority(uint16_t id, uint16_t priority)
996996
return ERR_TASK_NOT_FOUND;
997997
}
998998

999+
bool is_current = (kcb->task_current->data == task);
1000+
1001+
/* Removed task from ready queue */
1002+
if (task->state == TASK_RUNNING || task->state == TASK_READY) {
1003+
sched_dequeue_task(task);
1004+
1005+
/* Update new properties */
1006+
task->prio = priority;
1007+
task->prio_level = extract_priority_level(priority);
1008+
1009+
/* Enqueue task node into new priority ready queue*/
1010+
sched_enqueue_task(task);
1011+
}
1012+
9991013
/* Update priority and level */
10001014
task->prio = priority;
10011015
task->prio_level = extract_priority_level(priority);
10021016
task->time_slice = get_priority_timeslice(task->prio_level);
10031017

10041018
CRITICAL_LEAVE();
1019+
1020+
if (is_current)
1021+
mo_task_yield();
1022+
10051023
return ERR_OK;
10061024
}
10071025

0 commit comments

Comments
 (0)