Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/FreeRTOS/FreeRTOS-Kernel.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchinglee-iot <61685396+chinglee-iot@users.noreply.github.com>2024-01-23 12:02:15 +0300
committerGitHub <noreply@github.com>2024-01-23 12:02:15 +0300
commitcf2366c949735eec9c5eee83b5909bb913cd1679 (patch)
treec6f4220cc40cf143101ddf16609bd289986b5026
parente6f6d0ecf4a96bcd6e23e3334ac463056f939be8 (diff)
Update unpaired critical section in vTaskDelete for readability (#958)
* Modify unpaired critical section for readability * Move prvDeleteTCB out of critical section for SMP --------- Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com> Co-authored-by: Gaurav Aggarwal <aggarg@amazon.com>
-rw-r--r--tasks.c73
1 files changed, 36 insertions, 37 deletions
diff --git a/tasks.c b/tasks.c
index d00e96674..4a640d611 100644
--- a/tasks.c
+++ b/tasks.c
@@ -2190,6 +2190,7 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
void vTaskDelete( TaskHandle_t xTaskToDelete )
{
TCB_t * pxTCB;
+ BaseType_t xDeleteTCBInIdleTask = pdFALSE;
traceENTER_vTaskDelete( xTaskToDelete );
@@ -2247,6 +2248,9 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
* portPRE_TASK_DELETE_HOOK() does not return in the Win32 port. */
traceTASK_DELETE( pxTCB );
+ /* Delete the task TCB in idle task. */
+ xDeleteTCBInIdleTask = pdTRUE;
+
/* The pre-delete hook is primarily for the Windows simulator,
* in which Windows specific clean up operations are performed,
* after which it is not possible to yield away from this task -
@@ -2268,61 +2272,56 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
prvResetNextTaskUnblockTime();
}
}
+ taskEXIT_CRITICAL();
- #if ( configNUMBER_OF_CORES == 1 )
+ /* If the task is not deleting itself, call prvDeleteTCB from outside of
+ * critical section. If a task deletes itself, prvDeleteTCB is called
+ * from prvCheckTasksWaitingTermination which is called from Idle task. */
+ if( xDeleteTCBInIdleTask != pdTRUE )
{
- taskEXIT_CRITICAL();
-
- /* If the task is not deleting itself, call prvDeleteTCB from outside of
- * critical section. If a task deletes itself, prvDeleteTCB is called
- * from prvCheckTasksWaitingTermination which is called from Idle task. */
- if( pxTCB != pxCurrentTCB )
- {
- prvDeleteTCB( pxTCB );
- }
+ prvDeleteTCB( pxTCB );
+ }
- /* Force a reschedule if it is the currently running task that has just
- * been deleted. */
- if( xSchedulerRunning != pdFALSE )
+ /* Force a reschedule if it is the currently running task that has just
+ * been deleted. */
+ if( xSchedulerRunning != pdFALSE )
+ {
+ #if ( configNUMBER_OF_CORES == 1 )
{
if( pxTCB == pxCurrentTCB )
{
configASSERT( uxSchedulerSuspended == 0 );
- portYIELD_WITHIN_API();
+ taskYIELD_WITHIN_API();
}
else
{
mtCOVERAGE_TEST_MARKER();
}
}
- }
- #else /* #if ( configNUMBER_OF_CORES == 1 ) */
- {
- /* If a running task is not deleting itself, call prvDeleteTCB. If a running
- * task deletes itself, prvDeleteTCB is called from prvCheckTasksWaitingTermination
- * which is called from Idle task. */
- if( pxTCB->xTaskRunState == taskTASK_NOT_RUNNING )
- {
- prvDeleteTCB( pxTCB );
- }
-
- /* Force a reschedule if the task that has just been deleted was running. */
- if( ( xSchedulerRunning != pdFALSE ) && ( taskTASK_IS_RUNNING( pxTCB ) == pdTRUE ) )
+ #else /* #if ( configNUMBER_OF_CORES == 1 ) */
{
- if( pxTCB->xTaskRunState == ( BaseType_t ) portGET_CORE_ID() )
- {
- configASSERT( uxSchedulerSuspended == 0 );
- vTaskYieldWithinAPI();
- }
- else
+ /* It is important to use critical section here because
+ * checking run state of a task must be done inside a
+ * critical section. */
+ taskENTER_CRITICAL();
{
- prvYieldCore( pxTCB->xTaskRunState );
+ if( taskTASK_IS_RUNNING( pxTCB ) == pdTRUE )
+ {
+ if( pxTCB->xTaskRunState == ( BaseType_t ) portGET_CORE_ID() )
+ {
+ configASSERT( uxSchedulerSuspended == 0 );
+ taskYIELD_WITHIN_API();
+ }
+ else
+ {
+ prvYieldCore( pxTCB->xTaskRunState );
+ }
+ }
}
+ taskEXIT_CRITICAL();
}
-
- taskEXIT_CRITICAL();
+ #endif /* #if ( configNUMBER_OF_CORES == 1 ) */
}
- #endif /* #if ( configNUMBER_OF_CORES == 1 ) */
traceRETURN_vTaskDelete();
}