Commit 202b115
committed
Add enqueue and dequeue paths to task operation APIs
Previously, task operation APIs such as sched_wakeup_task() only updated
the task state, which was sufficient when scheduling relied on the global
task list. With the scheduler now selecting runnable tasks from
ready_queue[] per priority level, state changes alone are insufficient.
To support the new scheduler and to prevent selection of tasks that have
already left the runnable set, explicit enqueue and dequeue paths are
required when task state transitions cross the runnable boundary:
In ready-queue set: {TASK_RUNNING, TASK_READY}
Not in ready-queue set: {all other states}
This change updates task operation APIs to include queue insertion and
removal logic according to their semantics. In general, queue operations
are performed by invoking existing helper functions sched_enqueue_task()
and sched_dequeue_task().
The modified APIs include:
- sched_wakeup_task(): avoid enqueueing a task that is already running
by treating TASK_RUNNING as part of the runnable set complement.
- mo_task_cancel(): dequeue TASK_READY tasks from ready_queue[] before
cancelling, ensuring removed tasks are not scheduled again.
- mo_task_delay(): runnable boundary transition only ("TASK_RUNNING →
TASK_BLOCKED"), no queue insertion for non-runnable tasks.
- mo_task_suspend(): supports both TASK_RUNNING and TASK_READY
("TASK_RUNNING/TASK_READY → TASK_SUSPENDED"), dequeue before suspend
when necessary.
- mo_task_resume(): only for suspended tasks ("TASK_SUSPENDED →
TASK_READY"), enqueue into ready_queue[] on resume.
- _sched_block(): runnable boundary transition only ("TASK_RUNNING →
TASK_BLOCKED"), dequeue without memory free.
This change keeps task state transition consistent to the ready queue
semantic.1 parent 95d9f81 commit 202b115
1 file changed
+21
-13
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
439 | 439 | | |
440 | 440 | | |
441 | 441 | | |
442 | | - | |
| 442 | + | |
443 | 443 | | |
444 | 444 | | |
445 | 445 | | |
446 | 446 | | |
447 | 447 | | |
448 | | - | |
449 | | - | |
450 | | - | |
451 | | - | |
452 | | - | |
453 | | - | |
454 | | - | |
455 | | - | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
456 | 451 | | |
457 | 452 | | |
458 | 453 | | |
| |||
864 | 859 | | |
865 | 860 | | |
866 | 861 | | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
867 | 866 | | |
868 | 867 | | |
869 | 868 | | |
| |||
893 | 892 | | |
894 | 893 | | |
895 | 894 | | |
896 | | - | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
897 | 898 | | |
898 | 899 | | |
899 | 900 | | |
| |||
920 | 921 | | |
921 | 922 | | |
922 | 923 | | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
923 | 929 | | |
924 | 930 | | |
925 | 931 | | |
| |||
948 | 954 | | |
949 | 955 | | |
950 | 956 | | |
951 | | - | |
952 | | - | |
953 | | - | |
| 957 | + | |
| 958 | + | |
954 | 959 | | |
955 | 960 | | |
956 | 961 | | |
| |||
1072 | 1077 | | |
1073 | 1078 | | |
1074 | 1079 | | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
1075 | 1083 | | |
1076 | 1084 | | |
1077 | 1085 | | |
| |||
0 commit comments