Skip to content

Commit

Permalink
Merge branch 'main' into add-yield-within-api-macro
Browse files Browse the repository at this point in the history
  • Loading branch information
chinglee-iot authored Sep 6, 2023
2 parents df3e8a6 + c93d386 commit 8120fef
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions tasks.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,14 +265,11 @@
#define taskEVENT_LIST_ITEM_VALUE_IN_USE 0x8000000000000000ULL
#endif

/* Task state. */
typedef BaseType_t TaskRunning_t;

/* Indicates that the task is not actively running on any core. */
#define taskTASK_NOT_RUNNING ( TaskRunning_t ) ( -1 )
#define taskTASK_NOT_RUNNING ( ( BaseType_t ) ( -1 ) )

/* Indicates that the task is actively running but scheduled to yield. */
#define taskTASK_YIELDING ( TaskRunning_t ) ( -2 )
#define taskTASK_SCHEDULED_TO_YIELD ( ( BaseType_t ) ( -2 ) )

/* Returns pdTRUE if the task is actively running and not scheduled to yield. */
#if ( configNUMBER_OF_CORES == 1 )
Expand Down Expand Up @@ -319,7 +316,7 @@ typedef struct tskTaskControlBlock /* The old naming convention is used to
UBaseType_t uxPriority; /**< The priority of the task. 0 is the lowest priority. */
StackType_t * pxStack; /**< Points to the start of the stack. */
#if ( configNUMBER_OF_CORES > 1 )
volatile TaskRunning_t xTaskRunState; /**< Used to identify the core the task is running on, if the task is running. Otherwise, identifies the task's state - not running or yielding. */
volatile BaseType_t xTaskRunState; /**< Used to identify the core the task is running on, if the task is running. Otherwise, identifies the task's state - not running or yielding. */
UBaseType_t uxTaskAttributes; /**< Task's attributes - currently used to identify the idle tasks. */
#endif
char pcTaskName[ configMAX_TASK_NAME_LEN ]; /**< Descriptive name given to the task when created. Facilitates debugging only. */ /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
Expand Down Expand Up @@ -706,7 +703,7 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION;
* so this is safe. */
pxThisTCB = pxCurrentTCBs[ portGET_CORE_ID() ];

while( pxThisTCB->xTaskRunState == taskTASK_YIELDING )
while( pxThisTCB->xTaskRunState == taskTASK_SCHEDULED_TO_YIELD )
{
/* We are only here if we just entered a critical section
* or if we just suspended the scheduler, and another task
Expand All @@ -731,16 +728,15 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION;
}

portRELEASE_TASK_LOCK();

portMEMORY_BARRIER();
configASSERT( pxThisTCB->xTaskRunState == taskTASK_YIELDING );
configASSERT( pxThisTCB->xTaskRunState == taskTASK_SCHEDULED_TO_YIELD );

portENABLE_INTERRUPTS();

/* Enabling interrupts should cause this core to immediately
* service the pending interrupt and yield. If the run state is still
* yielding here then that is a problem. */
configASSERT( pxThisTCB->xTaskRunState != taskTASK_YIELDING );
configASSERT( pxThisTCB->xTaskRunState != taskTASK_SCHEDULED_TO_YIELD );

portDISABLE_INTERRUPTS();
portGET_TASK_LOCK();
Expand Down Expand Up @@ -768,7 +764,7 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION;
}
else
{
if( pxCurrentTCBs[ xCoreID ]->xTaskRunState != taskTASK_YIELDING )
if( pxCurrentTCBs[ xCoreID ]->xTaskRunState != taskTASK_SCHEDULED_TO_YIELD )
{
if( xCoreID == ( BaseType_t ) portGET_CORE_ID() )
{
Expand All @@ -777,7 +773,7 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION;
else
{
portYIELD_CORE( xCoreID );
pxCurrentTCBs[ xCoreID ]->xTaskRunState = taskTASK_YIELDING;
pxCurrentTCBs[ xCoreID ]->xTaskRunState = taskTASK_SCHEDULED_TO_YIELD;
}
}
}
Expand Down Expand Up @@ -988,21 +984,21 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION;
#if ( configUSE_CORE_AFFINITY == 1 )
pxPreviousTCB = pxCurrentTCBs[ xCoreID ];
#endif
pxTCB->xTaskRunState = ( TaskRunning_t ) xCoreID;
pxTCB->xTaskRunState = xCoreID;
pxCurrentTCBs[ xCoreID ] = pxTCB;
xTaskScheduled = pdTRUE;
}
}
else if( pxTCB == pxCurrentTCBs[ xCoreID ] )
{
configASSERT( ( pxTCB->xTaskRunState == xCoreID ) || ( pxTCB->xTaskRunState == taskTASK_YIELDING ) );
configASSERT( ( pxTCB->xTaskRunState == xCoreID ) || ( pxTCB->xTaskRunState == taskTASK_SCHEDULED_TO_YIELD ) );

#if ( configUSE_CORE_AFFINITY == 1 )
if( ( pxTCB->uxCoreAffinityMask & ( ( UBaseType_t ) 1U << ( UBaseType_t ) xCoreID ) ) != 0U )
#endif
{
/* The task is already running on this core, mark it as scheduled. */
pxTCB->xTaskRunState = ( TaskRunning_t ) xCoreID;
pxTCB->xTaskRunState = xCoreID;
xTaskScheduled = pdTRUE;
}
}
Expand Down Expand Up @@ -2005,7 +2001,7 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
/* Force a reschedule if the task that has just been deleted was running. */
if( ( xSchedulerRunning != pdFALSE ) && ( taskTASK_IS_RUNNING( pxTCB ) == pdTRUE ) )
{
if( pxTCB->xTaskRunState == ( TaskRunning_t ) portGET_CORE_ID() )
if( pxTCB->xTaskRunState == ( BaseType_t ) portGET_CORE_ID() )
{
configASSERT( uxSchedulerSuspended == 0 );
vTaskYieldWithinAPI();
Expand Down Expand Up @@ -2702,7 +2698,7 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
TCB_t * pxTCB;

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

taskENTER_CRITICAL();
Expand Down Expand Up @@ -2825,7 +2821,7 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
{
if( xSchedulerRunning != pdFALSE )
{
if( xTaskRunningOnCore == ( TaskRunning_t ) portGET_CORE_ID() )
if( xTaskRunningOnCore == ( BaseType_t ) portGET_CORE_ID() )
{
/* The current task has just been suspended. */
configASSERT( uxSchedulerSuspended == 0 );
Expand Down

0 comments on commit 8120fef

Please sign in to comment.