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-24 14:48:31 +0300
committerGitHub <noreply@github.com>2024-01-24 14:48:31 +0300
commit72c7d862762425832d9fce2df7b03d2ad355cb1e (patch)
treec12bc2994dbdadab01a94959bf9457d23945272c
parent4d9f6522e574410a20cb1430aaa1a667a564ec4b (diff)
Update for unpaired critical section in vTaskSuspend (#959)HEADmain
* Move the taskEXIT_CRITICAL out of the configNUMBER_OF_CORES macro block to improve readability.
-rw-r--r--tasks.c85
1 files changed, 34 insertions, 51 deletions
diff --git a/tasks.c b/tasks.c
index 4a640d611..26a442637 100644
--- a/tasks.c
+++ b/tasks.c
@@ -3107,10 +3107,6 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
{
TCB_t * pxTCB;
- #if ( configNUMBER_OF_CORES > 1 )
- BaseType_t xTaskRunningOnCore;
- #endif
-
traceENTER_vTaskSuspend( xTaskToSuspend );
taskENTER_CRITICAL();
@@ -3121,10 +3117,6 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
traceTASK_SUSPEND( pxTCB );
- #if ( configNUMBER_OF_CORES > 1 )
- xTaskRunningOnCore = pxTCB->xTaskRunState;
- #endif
-
/* Remove task from the ready/delayed list and place in the
* suspended list. */
if( uxListRemove( &( pxTCB->xStateListItem ) ) == ( UBaseType_t ) 0 )
@@ -3164,26 +3156,25 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
}
#endif /* if ( configUSE_TASK_NOTIFICATIONS == 1 ) */
}
+ taskEXIT_CRITICAL();
- #if ( configNUMBER_OF_CORES == 1 )
+ if( xSchedulerRunning != pdFALSE )
{
- taskEXIT_CRITICAL();
-
- if( xSchedulerRunning != pdFALSE )
- {
- /* Reset the next expected unblock time in case it referred to the
- * task that is now in the Suspended state. */
- taskENTER_CRITICAL();
- {
- prvResetNextTaskUnblockTime();
- }
- taskEXIT_CRITICAL();
- }
- else
+ /* Reset the next expected unblock time in case it referred to the
+ * task that is now in the Suspended state. */
+ taskENTER_CRITICAL();
{
- mtCOVERAGE_TEST_MARKER();
+ prvResetNextTaskUnblockTime();
}
+ taskEXIT_CRITICAL();
+ }
+ else
+ {
+ mtCOVERAGE_TEST_MARKER();
+ }
+ #if ( configNUMBER_OF_CORES == 1 )
+ {
if( pxTCB == pxCurrentTCB )
{
if( xSchedulerRunning != pdFALSE )
@@ -3218,47 +3209,39 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
}
#else /* #if ( configNUMBER_OF_CORES == 1 ) */
{
- if( xSchedulerRunning != pdFALSE )
- {
- /* Reset the next expected unblock time in case it referred to the
- * task that is now in the Suspended state. */
- prvResetNextTaskUnblockTime();
- }
- else
- {
- mtCOVERAGE_TEST_MARKER();
- }
-
- if( taskTASK_IS_RUNNING( pxTCB ) == pdTRUE )
+ /* Enter critical section here to check run state of a task. */
+ taskENTER_CRITICAL();
{
- if( xSchedulerRunning != pdFALSE )
+ if( taskTASK_IS_RUNNING( pxTCB ) == pdTRUE )
{
- if( xTaskRunningOnCore == ( BaseType_t ) portGET_CORE_ID() )
+ if( xSchedulerRunning != pdFALSE )
{
- /* The current task has just been suspended. */
- configASSERT( uxSchedulerSuspended == 0 );
- vTaskYieldWithinAPI();
+ if( pxTCB->xTaskRunState == ( BaseType_t ) portGET_CORE_ID() )
+ {
+ /* The current task has just been suspended. */
+ configASSERT( uxSchedulerSuspended == 0 );
+ vTaskYieldWithinAPI();
+ }
+ else
+ {
+ prvYieldCore( pxTCB->xTaskRunState );
+ }
}
else
{
- prvYieldCore( xTaskRunningOnCore );
+ /* This code path is not possible because only Idle tasks are
+ * assigned a core before the scheduler is started ( i.e.
+ * taskTASK_IS_RUNNING is only true for idle tasks before
+ * the scheduler is started ) and idle tasks cannot be
+ * suspended. */
+ mtCOVERAGE_TEST_MARKER();
}
}
else
{
- /* This code path is not possible because only Idle tasks are
- * assigned a core before the scheduler is started ( i.e.
- * taskTASK_IS_RUNNING is only true for idle tasks before
- * the scheduler is started ) and idle tasks cannot be
- * suspended. */
mtCOVERAGE_TEST_MARKER();
}
}
- else
- {
- mtCOVERAGE_TEST_MARKER();
- }
-
taskEXIT_CRITICAL();
}
#endif /* #if ( configNUMBER_OF_CORES == 1 ) */