Skip to content

Commit f13ad77

Browse files
authored
Add macro taskTASK_IS_RUNNING_OR_SCHEDULED_TO_YIELD (#780)
* Add macro taskTASK_IS_RUNNING_OR_SCHEDULED_TO_YIELD macro to align single core and SMP * Update for explicit precedence in vTaskDelete * Update comment when deleting a running task
1 parent f7565c2 commit f13ad77

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

tasks.c

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,11 @@
267267

268268
/* Returns pdTRUE if the task is actively running and not scheduled to yield. */
269269
#if ( configNUMBER_OF_CORES == 1 )
270-
#define taskTASK_IS_RUNNING( pxTCB ) ( ( ( pxTCB ) == pxCurrentTCB ) ? ( pdTRUE ) : ( pdFALSE ) )
270+
#define taskTASK_IS_RUNNING( pxTCB ) ( ( ( pxTCB ) == pxCurrentTCB ) ? ( pdTRUE ) : ( pdFALSE ) )
271+
#define taskTASK_IS_RUNNING_OR_SCHEDULED_TO_YIELD( pxTCB ) ( ( ( pxTCB ) == pxCurrentTCB ) ? ( pdTRUE ) : ( pdFALSE ) )
271272
#else
272-
#define taskTASK_IS_RUNNING( pxTCB ) ( ( ( ( pxTCB )->xTaskRunState >= ( BaseType_t ) 0 ) && ( ( pxTCB )->xTaskRunState < ( BaseType_t ) configNUMBER_OF_CORES ) ) ? ( pdTRUE ) : ( pdFALSE ) )
273+
#define taskTASK_IS_RUNNING( pxTCB ) ( ( ( ( pxTCB )->xTaskRunState >= ( BaseType_t ) 0 ) && ( ( pxTCB )->xTaskRunState < ( BaseType_t ) configNUMBER_OF_CORES ) ) ? ( pdTRUE ) : ( pdFALSE ) )
274+
#define taskTASK_IS_RUNNING_OR_SCHEDULED_TO_YIELD( pxTCB ) ( ( ( pxTCB )->xTaskRunState != taskTASK_NOT_RUNNING ) ? ( pdTRUE ) : ( pdFALSE ) )
273275
#endif
274276

275277
/* Indicates that the task is an Idle task. */
@@ -1913,17 +1915,14 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
19131915
/* If the task is running (or yielding), we must add it to the
19141916
* termination list so that an idle task can delete it when it is
19151917
* no longer running. */
1916-
#if ( configNUMBER_OF_CORES == 1 )
1917-
if( pxTCB == pxCurrentTCB )
1918-
#else
1919-
if( pxTCB->xTaskRunState != taskTASK_NOT_RUNNING )
1920-
#endif
1921-
{
1922-
/* A running task is being deleted. This cannot complete within the
1923-
* task itself, as a context switch to another task is required.
1924-
* Place the task in the termination list. The idle task will
1925-
* check the termination list and free up any memory allocated by
1926-
* the scheduler for the TCB and stack of the deleted task. */
1918+
if( taskTASK_IS_RUNNING_OR_SCHEDULED_TO_YIELD( pxTCB ) != pdFALSE )
1919+
{
1920+
/* A running task or a task which is scheduled to yield is being
1921+
* deleted. This cannot complete when the task is still running
1922+
* on a core, as a context switch to another task is required.
1923+
* Place the task in the termination list. The idle task will check
1924+
* the termination list and free up any memory allocated by the
1925+
* scheduler for the TCB and stack of the deleted task. */
19271926
vListInsertEnd( &xTasksWaitingTermination, &( pxTCB->xStateListItem ) );
19281927

19291928
/* Increment the ucTasksDeleted variable so the idle task knows
@@ -1941,9 +1940,9 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
19411940
* hence xYieldPending is used to latch that a context switch is
19421941
* required. */
19431942
#if ( configNUMBER_OF_CORES == 1 )
1944-
portPRE_TASK_DELETE_HOOK( pxTCB, &xYieldPendings[ 0 ] );
1943+
portPRE_TASK_DELETE_HOOK( pxTCB, &( xYieldPendings[ 0 ] ) );
19451944
#else
1946-
portPRE_TASK_DELETE_HOOK( pxTCB, &xYieldPendings[ pxTCB->xTaskRunState ] );
1945+
portPRE_TASK_DELETE_HOOK( pxTCB, &( xYieldPendings[ pxTCB->xTaskRunState ] ) );
19471946
#endif
19481947
}
19491948
else

0 commit comments

Comments
 (0)