Skip to content

Commit 1072988

Browse files
authored
Fix context switch when time slicing is off (#568)
* 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]>
1 parent 44e02bf commit 1072988

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

tasks.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2812,10 +2812,14 @@ BaseType_t xTaskIncrementTick( void )
28122812
#if ( configUSE_PREEMPTION == 1 )
28132813
{
28142814
/* Preemption is on, but a context switch should
2815-
* only be performed if the unblocked task has a
2816-
* priority that is equal to or higher than the
2817-
* currently executing task. */
2818-
if( pxTCB->uxPriority >= pxCurrentTCB->uxPriority )
2815+
* only be performed if the unblocked task's
2816+
* priority is higher than the currently executing
2817+
* task.
2818+
* The case of equal priority tasks sharing
2819+
* processing time (which happens when both
2820+
* preemption and time slicing are on) is
2821+
* handled below.*/
2822+
if( pxTCB->uxPriority > pxCurrentTCB->uxPriority )
28192823
{
28202824
xSwitchRequired = pdTRUE;
28212825
}

0 commit comments

Comments
 (0)