Skip to content

Commit

Permalink
Merge branch 'bugfix/freertos_nested_sched_suspension_v5.1' into 'rel…
Browse files Browse the repository at this point in the history
…ease/v5.1'

freertos-idf: Fixed incorrect scheduler suspension check in xTaskRemoveFromEventList() (v5.1)

See merge request espressif/esp-idf!23650
  • Loading branch information
zikalino committed May 9, 2023
2 parents 5a353ab + ee18b19 commit f5020d3
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions components/freertos/FreeRTOS-Kernel/tasks.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,11 @@
* - Check the scheduler suspension state on core 0. The task can be scheduled if the scheduler is not suspended.
*/
#if ( configNUM_CORES > 1 )
#define taskCAN_BE_SCHEDULED( pxTCB ) \
( ( pxTCB->xCoreID != tskNO_AFFINITY ) ) ? ( uxSchedulerSuspended[ pxTCB->xCoreID ] == ( UBaseType_t ) pdFALSE ) : \
( ( uxSchedulerSuspended[ 0 ] == ( UBaseType_t ) pdFALSE ) || ( uxSchedulerSuspended[ 1 ] == ( UBaseType_t ) pdFALSE ) )
#define taskCAN_BE_SCHEDULED( pxTCB ) \
( ( pxTCB->xCoreID != tskNO_AFFINITY ) ) ? ( uxSchedulerSuspended[ pxTCB->xCoreID ] == ( UBaseType_t ) 0U ) : \
( ( uxSchedulerSuspended[ 0 ] == ( UBaseType_t ) 0U ) || ( uxSchedulerSuspended[ 1 ] == ( UBaseType_t ) 0U ) )
#else
#define taskCAN_BE_SCHEDULED( pxTCB ) ( ( uxSchedulerSuspended[ 0 ] == ( UBaseType_t ) pdFALSE ) )
#define taskCAN_BE_SCHEDULED( pxTCB ) ( ( uxSchedulerSuspended[ 0 ] == ( UBaseType_t ) 0U ) )
#endif /* configNUM_CORES > 1 */

/*
Expand Down Expand Up @@ -318,7 +318,7 @@
#if ( configNUM_CORES > 1 )
#define taskIS_SCHEDULER_SUSPENDED() ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED )
#else
#define taskIS_SCHEDULER_SUSPENDED() ( uxSchedulerSuspended[ 0 ] > 0 )
#define taskIS_SCHEDULER_SUSPENDED() ( ( uxSchedulerSuspended[ 0 ] != ( UBaseType_t ) 0U ) )
#endif /* configNUM_CORES > 1 */

/* The item value of the event list item is normally used to hold the priority
Expand Down Expand Up @@ -485,7 +485,7 @@ PRIVILEGED_DATA static TaskHandle_t xIdleTaskHandle[ configNUM_CORES ] = { NULL
* kernel to move the task from the pending ready list into the real ready list
* when the scheduler is unsuspended. The pending ready list itself can only be
* accessed from a critical section. */
PRIVILEGED_DATA static volatile UBaseType_t uxSchedulerSuspended[ configNUM_CORES ] = { ( UBaseType_t ) pdFALSE };
PRIVILEGED_DATA static volatile UBaseType_t uxSchedulerSuspended[ configNUM_CORES ] = { ( UBaseType_t ) 0U };

#if ( configGENERATE_RUN_TIME_STATS == 1 )

Expand Down Expand Up @@ -1384,15 +1384,15 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB )
/* If the target task can run on the current core, and has a higher priority than the current core, and the core has not suspended scheduling, then yield the current core */
if( ( ( xTaskCoreID == xCurCoreID ) || ( xTaskCoreID == tskNO_AFFINITY ) ) &&
( uxTaskPriority > pxCurrentTCB[ xCurCoreID ]->uxPriority ) &&
( uxSchedulerSuspended[ xCurCoreID ] == ( UBaseType_t ) pdFALSE ) )
( uxSchedulerSuspended[ xCurCoreID ] == ( UBaseType_t ) 0U ) )
{
/* Return true for the caller to yield the current core */
xYieldRequiredCurrentCore = pdTRUE;
}
/* If the target task can run on the other core, and has a higher priority then the other core, and the other core has not suspended scheduling, then yield the other core */
else if( ( ( xTaskCoreID == !xCurCoreID ) || ( xTaskCoreID == tskNO_AFFINITY ) ) &&
( uxTaskPriority > pxCurrentTCB[ !xCurCoreID ]->uxPriority ) &&
( uxSchedulerSuspended[ !xCurCoreID ] == ( UBaseType_t ) pdFALSE ) )
( uxSchedulerSuspended[ !xCurCoreID ] == ( UBaseType_t ) 0U ) )
{
/* Signal the other core to yield */
vPortYieldOtherCore( !xCurCoreID );
Expand Down Expand Up @@ -1529,7 +1529,7 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB )

if( taskIS_CURRENTLY_RUNNING_ON_CORE( pxTCB, xPortGetCoreID() ) )
{
configASSERT( uxSchedulerSuspended[ xPortGetCoreID() ] == 0 );
configASSERT( uxSchedulerSuspended[ xPortGetCoreID() ] == ( UBaseType_t ) 0U );
portYIELD_WITHIN_API();
}
else
Expand Down Expand Up @@ -2089,7 +2089,7 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB )
if( xSchedulerRunning != pdFALSE )
{
/* The current task has just been suspended. */
configASSERT( uxSchedulerSuspended[ xPortGetCoreID() ] == 0 );
configASSERT( uxSchedulerSuspended[ xPortGetCoreID() ] == ( UBaseType_t ) 0U );
portYIELD_WITHIN_API();
}
else
Expand Down Expand Up @@ -2594,7 +2594,7 @@ BaseType_t xTaskResumeAll( void )

--uxSchedulerSuspended[ xCoreID ];

if( uxSchedulerSuspended[ xCoreID ] == ( UBaseType_t ) pdFALSE )
if( uxSchedulerSuspended[ xCoreID ] == ( UBaseType_t ) 0U )
{
if( uxCurrentNumberOfTasks > ( UBaseType_t ) 0U )
{
Expand Down Expand Up @@ -3156,7 +3156,7 @@ BaseType_t xTaskIncrementTick( void )
taskENTER_CRITICAL_ISR( &xKernelLock );
#endif /* ( configNUM_CORES > 1 ) */

if( uxSchedulerSuspended[ 0 ] == ( UBaseType_t ) pdFALSE )
if( uxSchedulerSuspended[ 0 ] == ( UBaseType_t ) 0U )
{
/* Minor optimisation. The tick count cannot change in this
* block. */
Expand Down Expand Up @@ -3354,7 +3354,7 @@ BaseType_t xTaskIncrementTick( void )
* tasks to be unblocked. */
traceTASK_INCREMENT_TICK( xTickCount );

if( uxSchedulerSuspended[ xCoreID ] == ( UBaseType_t ) pdFALSE )
if( uxSchedulerSuspended[ xCoreID ] == ( UBaseType_t ) 0U )
{
/* We need take the kernel lock here as we are about to access
* kernel data structures. */
Expand Down Expand Up @@ -3634,7 +3634,7 @@ void vTaskSwitchContext( void )
taskENTER_CRITICAL_ISR( &xKernelLock );
#endif /* ( configNUM_CORES > 1 ) */

if( uxSchedulerSuspended[ xPortGetCoreID() ] != ( UBaseType_t ) pdFALSE )
if( uxSchedulerSuspended[ xPortGetCoreID() ] != ( UBaseType_t ) 0U )
{
/* The scheduler is currently suspended - do not allow a context
* switch. */
Expand Down Expand Up @@ -3776,7 +3776,7 @@ void vTaskPlaceOnUnorderedEventList( List_t * pxEventList,

/* THIS FUNCTION MUST BE CALLED WITH THE SCHEDULER SUSPENDED. It is used by
* the event groups implementation. */
configASSERT( uxSchedulerSuspended[ 0 ] != 0 );
configASSERT( uxSchedulerSuspended[ 0 ] != ( UBaseType_t ) 0U );
#endif /* configNUM_CORES > 1 */

/* Store the item value in the event list item. It is safe to access the
Expand Down Expand Up @@ -3930,7 +3930,7 @@ BaseType_t xTaskRemoveFromEventList( const List_t * const pxEventList )
#else
xPendingListCore = 0;
#endif /* configNUM_CORES > 1 */
configASSERT( uxSchedulerSuspended[ xPendingListCore ] == pdTRUE );
configASSERT( uxSchedulerSuspended[ xPendingListCore ] != ( UBaseType_t ) 0U );

/* The delayed and ready lists cannot be accessed, so hold this task
* pending until the scheduler is resumed. */
Expand Down Expand Up @@ -4005,7 +4005,7 @@ void vTaskRemoveFromUnorderedEventList( ListItem_t * pxEventListItem,

/* THIS FUNCTION MUST BE CALLED WITH THE SCHEDULER SUSPENDED. It is used by
* the event flags implementation. */
configASSERT( uxSchedulerSuspended[ 0 ] != pdFALSE );
configASSERT( uxSchedulerSuspended[ 0 ] != ( UBaseType_t ) 0U );
#endif /* configNUM_CORES > 1 */

/* Store the new item value in the event list. */
Expand Down Expand Up @@ -5003,7 +5003,7 @@ static void prvResetNextTaskUnblockTime( void )
}
else
{
if( uxSchedulerSuspended[ xPortGetCoreID() ] == ( UBaseType_t ) pdFALSE )
if( uxSchedulerSuspended[ xPortGetCoreID() ] == ( UBaseType_t ) 0U )
{
xReturn = taskSCHEDULER_RUNNING;
}
Expand Down

0 comments on commit f5020d3

Please sign in to comment.