From 8e898b7e5ccb609104d41563a76eed37cac29c5d Mon Sep 17 00:00:00 2001 From: Ching-Hsin Lee Date: Tue, 5 Sep 2023 22:00:32 +0800 Subject: [PATCH 1/4] Add macro taskTASK_IS_RUNNING_OR_YIELDING * Add taskTASK_IS_RUNNING_OR_YIELDING macro to align single core and SMP --- tasks.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/tasks.c b/tasks.c index 6cb233e7a5..db781ddcdf 100644 --- a/tasks.c +++ b/tasks.c @@ -270,9 +270,11 @@ typedef BaseType_t TaskRunning_t; /* Returns pdTRUE if the task is actively running and not scheduled to yield. */ #if ( configNUMBER_OF_CORES == 1 ) - #define taskTASK_IS_RUNNING( pxTCB ) ( ( ( pxTCB ) == pxCurrentTCB ) ? ( pdTRUE ) : ( pdFALSE ) ) + #define taskTASK_IS_RUNNING( pxTCB ) ( ( ( pxTCB ) == pxCurrentTCB ) ? ( pdTRUE ) : ( pdFALSE ) ) + #define taskTASK_IS_RUNNING_OR_YIELDING( pxTCB ) ( ( ( pxTCB ) == pxCurrentTCB ) ? ( pdTRUE ) : ( pdFALSE ) ) #else - #define taskTASK_IS_RUNNING( pxTCB ) ( ( ( ( pxTCB )->xTaskRunState >= ( BaseType_t ) 0 ) && ( ( pxTCB )->xTaskRunState < ( BaseType_t ) configNUMBER_OF_CORES ) ) ? ( pdTRUE ) : ( pdFALSE ) ) + #define taskTASK_IS_RUNNING( pxTCB ) ( ( ( ( pxTCB )->xTaskRunState >= ( BaseType_t ) 0 ) && ( ( pxTCB )->xTaskRunState < ( BaseType_t ) configNUMBER_OF_CORES ) ) ? ( pdTRUE ) : ( pdFALSE ) ) + #define taskTASK_IS_RUNNING_OR_YIELDING( pxTCB ) ( ( ( pxTCB )->xTaskRunState != taskTASK_NOT_RUNNING ) ? ( pdTRUE ) : ( pdFALSE ) ) #endif /* Indicates that the task is an Idle task. */ @@ -1919,11 +1921,7 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode, /* If the task is running (or yielding), we must add it to the * termination list so that an idle task can delete it when it is * no longer running. */ - #if ( configNUMBER_OF_CORES == 1 ) - if( pxTCB == pxCurrentTCB ) - #else - if( pxTCB->xTaskRunState != taskTASK_NOT_RUNNING ) - #endif + if( taskTASK_IS_RUNNING_OR_YIELDING( pxTCB ) != pdFALSE ) { /* A running task is being deleted. This cannot complete within the * task itself, as a context switch to another task is required. From 45241c9917e6f3e42ade8a98915d82c775e180dd Mon Sep 17 00:00:00 2001 From: Ching-Hsin Lee Date: Tue, 5 Sep 2023 22:35:11 +0800 Subject: [PATCH 2/4] Update for explicit precidence in vTaskDelete --- tasks.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tasks.c b/tasks.c index db781ddcdf..a7b02f0bd8 100644 --- a/tasks.c +++ b/tasks.c @@ -1945,9 +1945,9 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode, * hence xYieldPending is used to latch that a context switch is * required. */ #if ( configNUMBER_OF_CORES == 1 ) - portPRE_TASK_DELETE_HOOK( pxTCB, &xYieldPendings[ 0 ] ); + portPRE_TASK_DELETE_HOOK( pxTCB, &( xYieldPendings[ 0 ] ) ); #else - portPRE_TASK_DELETE_HOOK( pxTCB, &xYieldPendings[ pxTCB->xTaskRunState ] ); + portPRE_TASK_DELETE_HOOK( pxTCB, &( xYieldPendings[ pxTCB->xTaskRunState ] ) ); #endif } else From bfa99230477dc363deb1e521e5af3656e62c8ecb Mon Sep 17 00:00:00 2001 From: Ching-Hsin Lee Date: Wed, 6 Sep 2023 15:19:12 +0800 Subject: [PATCH 3/4] Update comment when deleting a running task --- tasks.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tasks.c b/tasks.c index a7b02f0bd8..56c06262ff 100644 --- a/tasks.c +++ b/tasks.c @@ -1923,11 +1923,12 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode, * no longer running. */ if( taskTASK_IS_RUNNING_OR_YIELDING( pxTCB ) != pdFALSE ) { - /* A running task is being deleted. This cannot complete within the - * task itself, as a context switch to another task is required. - * Place the task in the termination list. The idle task will - * check the termination list and free up any memory allocated by - * the scheduler for the TCB and stack of the deleted task. */ + /* A running or yielding task is being deleted. This cannot complete + * when the task is still running on core, as a context switch to + * another task is required. Place the task in the termination list. + * The idle task will check the termination list and free up any + * memory allocated by the scheduler for the TCB and stack of the + * deleted task. */ vListInsertEnd( &xTasksWaitingTermination, &( pxTCB->xStateListItem ) ); /* Increment the ucTasksDeleted variable so the idle task knows From 85b82ef88e11d2c54d16addac3f89c54ec4bcb15 Mon Sep 17 00:00:00 2001 From: Ching-Hsin Lee Date: Wed, 6 Sep 2023 17:36:03 +0800 Subject: [PATCH 4/4] Rename macro and comment --- tasks.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tasks.c b/tasks.c index bf15986c1f..ae30827b52 100644 --- a/tasks.c +++ b/tasks.c @@ -270,11 +270,11 @@ typedef BaseType_t TaskRunning_t; /* Returns pdTRUE if the task is actively running and not scheduled to yield. */ #if ( configNUMBER_OF_CORES == 1 ) - #define taskTASK_IS_RUNNING( pxTCB ) ( ( ( pxTCB ) == pxCurrentTCB ) ? ( pdTRUE ) : ( pdFALSE ) ) - #define taskTASK_IS_RUNNING_OR_YIELDING( pxTCB ) ( ( ( pxTCB ) == pxCurrentTCB ) ? ( pdTRUE ) : ( pdFALSE ) ) + #define taskTASK_IS_RUNNING( pxTCB ) ( ( ( pxTCB ) == pxCurrentTCB ) ? ( pdTRUE ) : ( pdFALSE ) ) + #define taskTASK_IS_RUNNING_OR_SCHEDULED_TO_YIELD( pxTCB ) ( ( ( pxTCB ) == pxCurrentTCB ) ? ( pdTRUE ) : ( pdFALSE ) ) #else - #define taskTASK_IS_RUNNING( pxTCB ) ( ( ( ( pxTCB )->xTaskRunState >= ( BaseType_t ) 0 ) && ( ( pxTCB )->xTaskRunState < ( BaseType_t ) configNUMBER_OF_CORES ) ) ? ( pdTRUE ) : ( pdFALSE ) ) - #define taskTASK_IS_RUNNING_OR_YIELDING( pxTCB ) ( ( ( pxTCB )->xTaskRunState != taskTASK_NOT_RUNNING ) ? ( pdTRUE ) : ( pdFALSE ) ) + #define taskTASK_IS_RUNNING( pxTCB ) ( ( ( ( pxTCB )->xTaskRunState >= ( BaseType_t ) 0 ) && ( ( pxTCB )->xTaskRunState < ( BaseType_t ) configNUMBER_OF_CORES ) ) ? ( pdTRUE ) : ( pdFALSE ) ) + #define taskTASK_IS_RUNNING_OR_SCHEDULED_TO_YIELD( pxTCB ) ( ( ( pxTCB )->xTaskRunState != taskTASK_NOT_RUNNING ) ? ( pdTRUE ) : ( pdFALSE ) ) #endif /* Indicates that the task is an Idle task. */ @@ -1921,14 +1921,14 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode, /* If the task is running (or yielding), we must add it to the * termination list so that an idle task can delete it when it is * no longer running. */ - if( taskTASK_IS_RUNNING_OR_YIELDING( pxTCB ) != pdFALSE ) - { - /* A running or yielding task is being deleted. This cannot complete - * when the task is still running on core, as a context switch to - * another task is required. Place the task in the termination list. - * The idle task will check the termination list and free up any - * memory allocated by the scheduler for the TCB and stack of the - * deleted task. */ + if( taskTASK_IS_RUNNING_OR_SCHEDULED_TO_YIELD( pxTCB ) != pdFALSE ) + { + /* A running task or a task which is scheduled to yield is being + * deleted. This cannot complete when the task is still running + * on a core, as a context switch to another task is required. + * Place the task in the termination list. The idle task will check + * the termination list and free up any memory allocated by the + * scheduler for the TCB and stack of the deleted task. */ vListInsertEnd( &xTasksWaitingTermination, &( pxTCB->xStateListItem ) ); /* Increment the ucTasksDeleted variable so the idle task knows