Skip to content

Commit c93d386

Browse files
chinglee-iotSkptak
andauthored
Update task running state type and related macros (#770)
* Remove unnecessary type TaskRunning_t * Rename taskTASK_YIELD to taskTASK_SCHEDULED_TO_YIELD --------- Co-authored-by: Soren Ptak <[email protected]>
1 parent 53229b1 commit c93d386

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

tasks.c

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -259,14 +259,11 @@
259259
#define taskEVENT_LIST_ITEM_VALUE_IN_USE 0x8000000000000000ULL
260260
#endif
261261

262-
/* Task state. */
263-
typedef BaseType_t TaskRunning_t;
264-
265262
/* Indicates that the task is not actively running on any core. */
266-
#define taskTASK_NOT_RUNNING ( TaskRunning_t ) ( -1 )
263+
#define taskTASK_NOT_RUNNING ( ( BaseType_t ) ( -1 ) )
267264

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

271268
/* Returns pdTRUE if the task is actively running and not scheduled to yield. */
272269
#if ( configNUMBER_OF_CORES == 1 )
@@ -313,7 +310,7 @@ typedef struct tskTaskControlBlock /* The old naming convention is used to
313310
UBaseType_t uxPriority; /**< The priority of the task. 0 is the lowest priority. */
314311
StackType_t * pxStack; /**< Points to the start of the stack. */
315312
#if ( configNUMBER_OF_CORES > 1 )
316-
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. */
313+
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. */
317314
UBaseType_t uxTaskAttributes; /**< Task's attributes - currently used to identify the idle tasks. */
318315
#endif
319316
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. */
@@ -700,7 +697,7 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION;
700697
* so this is safe. */
701698
pxThisTCB = pxCurrentTCBs[ portGET_CORE_ID() ];
702699

703-
while( pxThisTCB->xTaskRunState == taskTASK_YIELDING )
700+
while( pxThisTCB->xTaskRunState == taskTASK_SCHEDULED_TO_YIELD )
704701
{
705702
/* We are only here if we just entered a critical section
706703
* or if we just suspended the scheduler, and another task
@@ -725,16 +722,15 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION;
725722
}
726723

727724
portRELEASE_TASK_LOCK();
728-
729725
portMEMORY_BARRIER();
730-
configASSERT( pxThisTCB->xTaskRunState == taskTASK_YIELDING );
726+
configASSERT( pxThisTCB->xTaskRunState == taskTASK_SCHEDULED_TO_YIELD );
731727

732728
portENABLE_INTERRUPTS();
733729

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

739735
portDISABLE_INTERRUPTS();
740736
portGET_TASK_LOCK();
@@ -762,7 +758,7 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION;
762758
}
763759
else
764760
{
765-
if( pxCurrentTCBs[ xCoreID ]->xTaskRunState != taskTASK_YIELDING )
761+
if( pxCurrentTCBs[ xCoreID ]->xTaskRunState != taskTASK_SCHEDULED_TO_YIELD )
766762
{
767763
if( xCoreID == ( BaseType_t ) portGET_CORE_ID() )
768764
{
@@ -771,7 +767,7 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION;
771767
else
772768
{
773769
portYIELD_CORE( xCoreID );
774-
pxCurrentTCBs[ xCoreID ]->xTaskRunState = taskTASK_YIELDING;
770+
pxCurrentTCBs[ xCoreID ]->xTaskRunState = taskTASK_SCHEDULED_TO_YIELD;
775771
}
776772
}
777773
}
@@ -982,21 +978,21 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION;
982978
#if ( configUSE_CORE_AFFINITY == 1 )
983979
pxPreviousTCB = pxCurrentTCBs[ xCoreID ];
984980
#endif
985-
pxTCB->xTaskRunState = ( TaskRunning_t ) xCoreID;
981+
pxTCB->xTaskRunState = xCoreID;
986982
pxCurrentTCBs[ xCoreID ] = pxTCB;
987983
xTaskScheduled = pdTRUE;
988984
}
989985
}
990986
else if( pxTCB == pxCurrentTCBs[ xCoreID ] )
991987
{
992-
configASSERT( ( pxTCB->xTaskRunState == xCoreID ) || ( pxTCB->xTaskRunState == taskTASK_YIELDING ) );
988+
configASSERT( ( pxTCB->xTaskRunState == xCoreID ) || ( pxTCB->xTaskRunState == taskTASK_SCHEDULED_TO_YIELD ) );
993989

994990
#if ( configUSE_CORE_AFFINITY == 1 )
995991
if( ( pxTCB->uxCoreAffinityMask & ( ( UBaseType_t ) 1U << ( UBaseType_t ) xCoreID ) ) != 0U )
996992
#endif
997993
{
998994
/* The task is already running on this core, mark it as scheduled. */
999-
pxTCB->xTaskRunState = ( TaskRunning_t ) xCoreID;
995+
pxTCB->xTaskRunState = xCoreID;
1000996
xTaskScheduled = pdTRUE;
1001997
}
1002998
}
@@ -1999,7 +1995,7 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
19991995
/* Force a reschedule if the task that has just been deleted was running. */
20001996
if( ( xSchedulerRunning != pdFALSE ) && ( taskTASK_IS_RUNNING( pxTCB ) == pdTRUE ) )
20011997
{
2002-
if( pxTCB->xTaskRunState == ( TaskRunning_t ) portGET_CORE_ID() )
1998+
if( pxTCB->xTaskRunState == ( BaseType_t ) portGET_CORE_ID() )
20031999
{
20042000
configASSERT( uxSchedulerSuspended == 0 );
20052001
vTaskYieldWithinAPI();
@@ -2704,7 +2700,7 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
27042700
TCB_t * pxTCB;
27052701

27062702
#if ( configNUMBER_OF_CORES > 1 )
2707-
TaskRunning_t xTaskRunningOnCore;
2703+
BaseType_t xTaskRunningOnCore;
27082704
#endif
27092705

27102706
taskENTER_CRITICAL();
@@ -2827,7 +2823,7 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
28272823
{
28282824
if( xSchedulerRunning != pdFALSE )
28292825
{
2830-
if( xTaskRunningOnCore == ( TaskRunning_t ) portGET_CORE_ID() )
2826+
if( xTaskRunningOnCore == ( BaseType_t ) portGET_CORE_ID() )
28312827
{
28322828
/* The current task has just been suspended. */
28332829
configASSERT( uxSchedulerSuspended == 0 );

0 commit comments

Comments
 (0)