Skip to content

Commit

Permalink
Fix context switch when time slicing is off (#568)
Browse files Browse the repository at this point in the history
* Fix context switch when time slicing is off

When time slicing is off, context switch should only happen when a
task with priority higher than the currently executing one is unblocked.
Earlier the code was invoking a context switch even when a task with
priority equal the currently executing task was unblocked. This commit
fixes the code to only do a context switch when a higher priority
task is unblocked.

Signed-off-by: Gaurav Aggarwal <[email protected]>
  • Loading branch information
aggarg authored Nov 8, 2022
1 parent 44e02bf commit 1072988
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions tasks.c
Original file line number Diff line number Diff line change
Expand Up @@ -2812,10 +2812,14 @@ BaseType_t xTaskIncrementTick( void )
#if ( configUSE_PREEMPTION == 1 )
{
/* Preemption is on, but a context switch should
* only be performed if the unblocked task has a
* priority that is equal to or higher than the
* currently executing task. */
if( pxTCB->uxPriority >= pxCurrentTCB->uxPriority )
* only be performed if the unblocked task's
* priority is higher than the currently executing
* task.
* The case of equal priority tasks sharing
* processing time (which happens when both
* preemption and time slicing are on) is
* handled below.*/
if( pxTCB->uxPriority > pxCurrentTCB->uxPriority )
{
xSwitchRequired = pdTRUE;
}
Expand Down

0 comments on commit 1072988

Please sign in to comment.