Skip to content

Commit

Permalink
Update for unpaired critical section in vTaskSuspend (#959)
Browse files Browse the repository at this point in the history
* Move the taskEXIT_CRITICAL out of the configNUMBER_OF_CORES macro block to improve readability.
  • Loading branch information
chinglee-iot committed Jan 24, 2024
1 parent 4d9f652 commit 72c7d86
Showing 1 changed file with 34 additions and 51 deletions.
85 changes: 34 additions & 51 deletions tasks.c
Original file line number Diff line number Diff line change
Expand Up @@ -3107,10 +3107,6 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
{
TCB_t * pxTCB;

#if ( configNUMBER_OF_CORES > 1 )
BaseType_t xTaskRunningOnCore;
#endif

traceENTER_vTaskSuspend( xTaskToSuspend );

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

traceTASK_SUSPEND( pxTCB );

#if ( configNUMBER_OF_CORES > 1 )
xTaskRunningOnCore = pxTCB->xTaskRunState;
#endif

/* Remove task from the ready/delayed list and place in the
* suspended list. */
if( uxListRemove( &( pxTCB->xStateListItem ) ) == ( UBaseType_t ) 0 )
Expand Down Expand Up @@ -3164,26 +3156,25 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
}
#endif /* if ( configUSE_TASK_NOTIFICATIONS == 1 ) */
}
taskEXIT_CRITICAL();

#if ( configNUMBER_OF_CORES == 1 )
if( xSchedulerRunning != pdFALSE )
{
taskEXIT_CRITICAL();

if( xSchedulerRunning != pdFALSE )
{
/* Reset the next expected unblock time in case it referred to the
* task that is now in the Suspended state. */
taskENTER_CRITICAL();
{
prvResetNextTaskUnblockTime();
}
taskEXIT_CRITICAL();
}
else
/* Reset the next expected unblock time in case it referred to the
* task that is now in the Suspended state. */
taskENTER_CRITICAL();
{
mtCOVERAGE_TEST_MARKER();
prvResetNextTaskUnblockTime();
}
taskEXIT_CRITICAL();
}
else
{
mtCOVERAGE_TEST_MARKER();
}

#if ( configNUMBER_OF_CORES == 1 )
{
if( pxTCB == pxCurrentTCB )
{
if( xSchedulerRunning != pdFALSE )
Expand Down Expand Up @@ -3218,47 +3209,39 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
}
#else /* #if ( configNUMBER_OF_CORES == 1 ) */
{
if( xSchedulerRunning != pdFALSE )
{
/* Reset the next expected unblock time in case it referred to the
* task that is now in the Suspended state. */
prvResetNextTaskUnblockTime();
}
else
{
mtCOVERAGE_TEST_MARKER();
}

if( taskTASK_IS_RUNNING( pxTCB ) == pdTRUE )
/* Enter critical section here to check run state of a task. */
taskENTER_CRITICAL();
{
if( xSchedulerRunning != pdFALSE )
if( taskTASK_IS_RUNNING( pxTCB ) == pdTRUE )
{
if( xTaskRunningOnCore == ( BaseType_t ) portGET_CORE_ID() )
if( xSchedulerRunning != pdFALSE )
{
/* The current task has just been suspended. */
configASSERT( uxSchedulerSuspended == 0 );
vTaskYieldWithinAPI();
if( pxTCB->xTaskRunState == ( BaseType_t ) portGET_CORE_ID() )
{
/* The current task has just been suspended. */
configASSERT( uxSchedulerSuspended == 0 );
vTaskYieldWithinAPI();
}
else
{
prvYieldCore( pxTCB->xTaskRunState );
}
}
else
{
prvYieldCore( xTaskRunningOnCore );
/* This code path is not possible because only Idle tasks are
* assigned a core before the scheduler is started ( i.e.
* taskTASK_IS_RUNNING is only true for idle tasks before
* the scheduler is started ) and idle tasks cannot be
* suspended. */
mtCOVERAGE_TEST_MARKER();
}
}
else
{
/* This code path is not possible because only Idle tasks are
* assigned a core before the scheduler is started ( i.e.
* taskTASK_IS_RUNNING is only true for idle tasks before
* the scheduler is started ) and idle tasks cannot be
* suspended. */
mtCOVERAGE_TEST_MARKER();
}
}
else
{
mtCOVERAGE_TEST_MARKER();
}

taskEXIT_CRITICAL();
}
#endif /* #if ( configNUMBER_OF_CORES == 1 ) */
Expand Down

0 comments on commit 72c7d86

Please sign in to comment.