Skip to content

Commit 72c7d86

Browse files
authored
Update for unpaired critical section in vTaskSuspend (#959)
* Move the taskEXIT_CRITICAL out of the configNUMBER_OF_CORES macro block to improve readability.
1 parent 4d9f652 commit 72c7d86

File tree

1 file changed

+34
-51
lines changed

1 file changed

+34
-51
lines changed

tasks.c

Lines changed: 34 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -3107,10 +3107,6 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
31073107
{
31083108
TCB_t * pxTCB;
31093109

3110-
#if ( configNUMBER_OF_CORES > 1 )
3111-
BaseType_t xTaskRunningOnCore;
3112-
#endif
3113-
31143110
traceENTER_vTaskSuspend( xTaskToSuspend );
31153111

31163112
taskENTER_CRITICAL();
@@ -3121,10 +3117,6 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
31213117

31223118
traceTASK_SUSPEND( pxTCB );
31233119

3124-
#if ( configNUMBER_OF_CORES > 1 )
3125-
xTaskRunningOnCore = pxTCB->xTaskRunState;
3126-
#endif
3127-
31283120
/* Remove task from the ready/delayed list and place in the
31293121
* suspended list. */
31303122
if( uxListRemove( &( pxTCB->xStateListItem ) ) == ( UBaseType_t ) 0 )
@@ -3164,26 +3156,25 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
31643156
}
31653157
#endif /* if ( configUSE_TASK_NOTIFICATIONS == 1 ) */
31663158
}
3159+
taskEXIT_CRITICAL();
31673160

3168-
#if ( configNUMBER_OF_CORES == 1 )
3161+
if( xSchedulerRunning != pdFALSE )
31693162
{
3170-
taskEXIT_CRITICAL();
3171-
3172-
if( xSchedulerRunning != pdFALSE )
3173-
{
3174-
/* Reset the next expected unblock time in case it referred to the
3175-
* task that is now in the Suspended state. */
3176-
taskENTER_CRITICAL();
3177-
{
3178-
prvResetNextTaskUnblockTime();
3179-
}
3180-
taskEXIT_CRITICAL();
3181-
}
3182-
else
3163+
/* Reset the next expected unblock time in case it referred to the
3164+
* task that is now in the Suspended state. */
3165+
taskENTER_CRITICAL();
31833166
{
3184-
mtCOVERAGE_TEST_MARKER();
3167+
prvResetNextTaskUnblockTime();
31853168
}
3169+
taskEXIT_CRITICAL();
3170+
}
3171+
else
3172+
{
3173+
mtCOVERAGE_TEST_MARKER();
3174+
}
31863175

3176+
#if ( configNUMBER_OF_CORES == 1 )
3177+
{
31873178
if( pxTCB == pxCurrentTCB )
31883179
{
31893180
if( xSchedulerRunning != pdFALSE )
@@ -3218,47 +3209,39 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
32183209
}
32193210
#else /* #if ( configNUMBER_OF_CORES == 1 ) */
32203211
{
3221-
if( xSchedulerRunning != pdFALSE )
3222-
{
3223-
/* Reset the next expected unblock time in case it referred to the
3224-
* task that is now in the Suspended state. */
3225-
prvResetNextTaskUnblockTime();
3226-
}
3227-
else
3228-
{
3229-
mtCOVERAGE_TEST_MARKER();
3230-
}
3231-
3232-
if( taskTASK_IS_RUNNING( pxTCB ) == pdTRUE )
3212+
/* Enter critical section here to check run state of a task. */
3213+
taskENTER_CRITICAL();
32333214
{
3234-
if( xSchedulerRunning != pdFALSE )
3215+
if( taskTASK_IS_RUNNING( pxTCB ) == pdTRUE )
32353216
{
3236-
if( xTaskRunningOnCore == ( BaseType_t ) portGET_CORE_ID() )
3217+
if( xSchedulerRunning != pdFALSE )
32373218
{
3238-
/* The current task has just been suspended. */
3239-
configASSERT( uxSchedulerSuspended == 0 );
3240-
vTaskYieldWithinAPI();
3219+
if( pxTCB->xTaskRunState == ( BaseType_t ) portGET_CORE_ID() )
3220+
{
3221+
/* The current task has just been suspended. */
3222+
configASSERT( uxSchedulerSuspended == 0 );
3223+
vTaskYieldWithinAPI();
3224+
}
3225+
else
3226+
{
3227+
prvYieldCore( pxTCB->xTaskRunState );
3228+
}
32413229
}
32423230
else
32433231
{
3244-
prvYieldCore( xTaskRunningOnCore );
3232+
/* This code path is not possible because only Idle tasks are
3233+
* assigned a core before the scheduler is started ( i.e.
3234+
* taskTASK_IS_RUNNING is only true for idle tasks before
3235+
* the scheduler is started ) and idle tasks cannot be
3236+
* suspended. */
3237+
mtCOVERAGE_TEST_MARKER();
32453238
}
32463239
}
32473240
else
32483241
{
3249-
/* This code path is not possible because only Idle tasks are
3250-
* assigned a core before the scheduler is started ( i.e.
3251-
* taskTASK_IS_RUNNING is only true for idle tasks before
3252-
* the scheduler is started ) and idle tasks cannot be
3253-
* suspended. */
32543242
mtCOVERAGE_TEST_MARKER();
32553243
}
32563244
}
3257-
else
3258-
{
3259-
mtCOVERAGE_TEST_MARKER();
3260-
}
3261-
32623245
taskEXIT_CRITICAL();
32633246
}
32643247
#endif /* #if ( configNUMBER_OF_CORES == 1 ) */

0 commit comments

Comments
 (0)