File tree Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -600,13 +600,26 @@ pub(super) fn choose_next_running_task<System: Kernel>(
600
600
} ;
601
601
602
602
// The priority of the next task to run
603
+ //
604
+ // The default value is `usize::max_value() - 1` for the following reason:
605
+ // If `running_task` is in the Waiting state and there's no other task to
606
+ // schedule at the moment, we want to assign `None` to `running_task`. In
607
+ // this case, if the default value was the same as `prev_task_priority`,
608
+ // `prev_task_priority` would be equal to `next_task_priority`, and the
609
+ // `if` statement below would return too early. We make sure this does not
610
+ // happen by making the default value of `next_task_priority` lower.
611
+ //
612
+ // `usize::max_value()` never collides with an actual task priority because
613
+ // of the priority range restriction imposed by `CfgBuilder::
614
+ // num_task_priority_levels`.
603
615
let next_task_priority = System :: state ( )
604
616
. task_ready_bitmap
605
617
. read ( & * lock)
606
618
. find_set ( )
607
- . unwrap_or ( usize:: max_value ( ) ) ;
619
+ . unwrap_or ( usize:: max_value ( ) - 1 ) ;
608
620
609
- // Return if there's no task willing to take over the current one.
621
+ // Return if there's no task willing to take over the current one, and
622
+ // the current one can still run.
610
623
if prev_task_priority <= next_task_priority {
611
624
return ;
612
625
}
You can’t perform that action at this time.
0 commit comments