Skip to content

Commit 94c320c

Browse files
feat(freertos/smp): Allow vTaskPreemptionEnable() to be nested
Changed xPreemptionDisable to be a count rather than a pdTRUE/pdFALSE. This allows nested calls to vTaskPreemptionEnable(), where a yield only occurs when xPreemptionDisable is 0. Co-authored-by: Sudeep Mohanty <[email protected]>
1 parent f836da4 commit 94c320c

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

include/FreeRTOS.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3179,7 +3179,7 @@ typedef struct xSTATIC_TCB
31793179
#endif
31803180
uint8_t ucDummy7[ configMAX_TASK_NAME_LEN ];
31813181
#if ( configUSE_TASK_PREEMPTION_DISABLE == 1 )
3182-
BaseType_t xDummy25;
3182+
UBaseType_t xDummy25;
31833183
#endif
31843184
#if ( ( portSTACK_GROWTH > 0 ) || ( configRECORD_STACK_HIGH_ADDRESS == 1 ) )
31853185
void * pxDummy8;

tasks.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ typedef struct tskTaskControlBlock /* The old naming convention is used to
394394
char pcTaskName[ configMAX_TASK_NAME_LEN ]; /**< Descriptive name given to the task when created. Facilitates debugging only. */
395395

396396
#if ( configUSE_TASK_PREEMPTION_DISABLE == 1 )
397-
BaseType_t xPreemptionDisable; /**< Used to prevent the task from being preempted. */
397+
UBaseType_t xPreemptionDisable; /**< Used to prevent the task from being preempted. */
398398
#endif
399399

400400
#if ( ( portSTACK_GROWTH > 0 ) || ( configRECORD_STACK_HIGH_ADDRESS == 1 ) )
@@ -941,7 +941,7 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION;
941941
#endif
942942
{
943943
#if ( configUSE_TASK_PREEMPTION_DISABLE == 1 )
944-
if( pxCurrentTCBs[ xCoreID ]->xPreemptionDisable == pdFALSE )
944+
if( pxCurrentTCBs[ xCoreID ]->xPreemptionDisable == 0U )
945945
#endif
946946
{
947947
xLowestPriorityToPreempt = xCurrentCoreTaskPriority;
@@ -1247,7 +1247,7 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION;
12471247
( xYieldPendings[ uxCore ] == pdFALSE ) )
12481248
{
12491249
#if ( configUSE_TASK_PREEMPTION_DISABLE == 1 )
1250-
if( pxCurrentTCBs[ uxCore ]->xPreemptionDisable == pdFALSE )
1250+
if( pxCurrentTCBs[ uxCore ]->xPreemptionDisable == 0U )
12511251
#endif
12521252
{
12531253
xLowestPriority = xTaskPriority;
@@ -2880,7 +2880,7 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
28802880
* there may now be another task of higher priority that
28812881
* is ready to execute. */
28822882
#if ( configUSE_TASK_PREEMPTION_DISABLE == 1 )
2883-
if( pxTCB->xPreemptionDisable == pdFALSE )
2883+
if( pxTCB->xPreemptionDisable == 0U )
28842884
#endif
28852885
{
28862886
xYieldRequired = pdTRUE;
@@ -3101,7 +3101,7 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
31013101
pxTCB = prvGetTCBFromHandle( xTask );
31023102
configASSERT( pxTCB != NULL );
31033103

3104-
pxTCB->xPreemptionDisable = pdTRUE;
3104+
pxTCB->xPreemptionDisable++;
31053105
}
31063106
taskEXIT_CRITICAL();
31073107

@@ -3124,12 +3124,13 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
31243124
{
31253125
pxTCB = prvGetTCBFromHandle( xTask );
31263126
configASSERT( pxTCB != NULL );
3127+
configASSERT( pxTCB->xPreemptionDisable > 0U );
31273128

3128-
pxTCB->xPreemptionDisable = pdFALSE;
3129+
pxTCB->xPreemptionDisable--;
31293130

31303131
if( xSchedulerRunning != pdFALSE )
31313132
{
3132-
if( taskTASK_IS_RUNNING( pxTCB ) == pdTRUE )
3133+
if( ( pxTCB->xPreemptionDisable == 0U ) && ( taskTASK_IS_RUNNING( pxTCB ) == pdTRUE ) )
31333134
{
31343135
xCoreID = ( BaseType_t ) pxTCB->xTaskRunState;
31353136
prvYieldCore( xCoreID );
@@ -4928,7 +4929,7 @@ BaseType_t xTaskIncrementTick( void )
49284929
for( xCoreID = 0; xCoreID < ( BaseType_t ) configNUMBER_OF_CORES; xCoreID++ )
49294930
{
49304931
#if ( configUSE_TASK_PREEMPTION_DISABLE == 1 )
4931-
if( pxCurrentTCBs[ xCoreID ]->xPreemptionDisable == pdFALSE )
4932+
if( pxCurrentTCBs[ xCoreID ]->xPreemptionDisable == 0U )
49324933
#endif
49334934
{
49344935
if( xYieldPendings[ xCoreID ] != pdFALSE )

0 commit comments

Comments
 (0)