Skip to content

Commit 2be0ff8

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 <sudeep.mohanty@espressif.com>
1 parent 9b330c3 commit 2be0ff8

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
@@ -3161,7 +3161,7 @@ typedef struct xSTATIC_TCB
31613161
#endif
31623162
uint8_t ucDummy7[ configMAX_TASK_NAME_LEN ];
31633163
#if ( configUSE_TASK_PREEMPTION_DISABLE == 1 )
3164-
BaseType_t xDummy25;
3164+
UBaseType_t xDummy25;
31653165
#endif
31663166
#if ( ( portSTACK_GROWTH > 0 ) || ( configRECORD_STACK_HIGH_ADDRESS == 1 ) )
31673167
void * pxDummy8;

tasks.c

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

380380
#if ( configUSE_TASK_PREEMPTION_DISABLE == 1 )
381-
BaseType_t xPreemptionDisable; /**< Used to prevent the task from being preempted. */
381+
UBaseType_t xPreemptionDisable; /**< Used to prevent the task from being preempted. */
382382
#endif
383383

384384
#if ( ( portSTACK_GROWTH > 0 ) || ( configRECORD_STACK_HIGH_ADDRESS == 1 ) )
@@ -921,7 +921,7 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION;
921921
#endif
922922
{
923923
#if ( configUSE_TASK_PREEMPTION_DISABLE == 1 )
924-
if( pxCurrentTCBs[ xCoreID ]->xPreemptionDisable == pdFALSE )
924+
if( pxCurrentTCBs[ xCoreID ]->xPreemptionDisable == 0U )
925925
#endif
926926
{
927927
xLowestPriorityToPreempt = xCurrentCoreTaskPriority;
@@ -1227,7 +1227,7 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION;
12271227
( xYieldPendings[ uxCore ] == pdFALSE ) )
12281228
{
12291229
#if ( configUSE_TASK_PREEMPTION_DISABLE == 1 )
1230-
if( pxCurrentTCBs[ uxCore ]->xPreemptionDisable == pdFALSE )
1230+
if( pxCurrentTCBs[ uxCore ]->xPreemptionDisable == 0U )
12311231
#endif
12321232
{
12331233
xLowestPriority = xTaskPriority;
@@ -2850,7 +2850,7 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
28502850
* there may now be another task of higher priority that
28512851
* is ready to execute. */
28522852
#if ( configUSE_TASK_PREEMPTION_DISABLE == 1 )
2853-
if( pxTCB->xPreemptionDisable == pdFALSE )
2853+
if( pxTCB->xPreemptionDisable == 0U )
28542854
#endif
28552855
{
28562856
xYieldRequired = pdTRUE;
@@ -3067,7 +3067,7 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
30673067
{
30683068
pxTCB = prvGetTCBFromHandle( xTask );
30693069

3070-
pxTCB->xPreemptionDisable = pdTRUE;
3070+
pxTCB->xPreemptionDisable++;
30713071
}
30723072
taskEXIT_CRITICAL();
30733073

@@ -3089,12 +3089,13 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
30893089
taskENTER_CRITICAL();
30903090
{
30913091
pxTCB = prvGetTCBFromHandle( xTask );
3092+
configASSERT( pxTCB->xPreemptionDisable > 0U );
30923093

3093-
pxTCB->xPreemptionDisable = pdFALSE;
3094+
pxTCB->xPreemptionDisable--;
30943095

30953096
if( xSchedulerRunning != pdFALSE )
30963097
{
3097-
if( taskTASK_IS_RUNNING( pxTCB ) == pdTRUE )
3098+
if( ( pxTCB->xPreemptionDisable == 0U ) && ( taskTASK_IS_RUNNING( pxTCB ) == pdTRUE ) )
30983099
{
30993100
xCoreID = ( BaseType_t ) pxTCB->xTaskRunState;
31003101
prvYieldCore( xCoreID );
@@ -4889,7 +4890,7 @@ BaseType_t xTaskIncrementTick( void )
48894890
for( xCoreID = 0; xCoreID < ( BaseType_t ) configNUMBER_OF_CORES; xCoreID++ )
48904891
{
48914892
#if ( configUSE_TASK_PREEMPTION_DISABLE == 1 )
4892-
if( pxCurrentTCBs[ xCoreID ]->xPreemptionDisable == pdFALSE )
4893+
if( pxCurrentTCBs[ xCoreID ]->xPreemptionDisable == 0U )
48934894
#endif
48944895
{
48954896
if( xYieldPendings[ xCoreID ] != pdFALSE )

0 commit comments

Comments
 (0)