@@ -2190,6 +2190,7 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
2190
2190
void vTaskDelete ( TaskHandle_t xTaskToDelete )
2191
2191
{
2192
2192
TCB_t * pxTCB ;
2193
+ BaseType_t xDeleteTCBInIdleTask = pdFALSE ;
2193
2194
2194
2195
traceENTER_vTaskDelete ( xTaskToDelete );
2195
2196
@@ -2247,6 +2248,9 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
2247
2248
* portPRE_TASK_DELETE_HOOK() does not return in the Win32 port. */
2248
2249
traceTASK_DELETE ( pxTCB );
2249
2250
2251
+ /* Delete the task TCB in idle task. */
2252
+ xDeleteTCBInIdleTask = pdTRUE ;
2253
+
2250
2254
/* The pre-delete hook is primarily for the Windows simulator,
2251
2255
* in which Windows specific clean up operations are performed,
2252
2256
* after which it is not possible to yield away from this task -
@@ -2268,61 +2272,56 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
2268
2272
prvResetNextTaskUnblockTime ();
2269
2273
}
2270
2274
}
2275
+ taskEXIT_CRITICAL ();
2271
2276
2272
- #if ( configNUMBER_OF_CORES == 1 )
2277
+ /* If the task is not deleting itself, call prvDeleteTCB from outside of
2278
+ * critical section. If a task deletes itself, prvDeleteTCB is called
2279
+ * from prvCheckTasksWaitingTermination which is called from Idle task. */
2280
+ if ( xDeleteTCBInIdleTask != pdTRUE )
2273
2281
{
2274
- taskEXIT_CRITICAL ();
2275
-
2276
- /* If the task is not deleting itself, call prvDeleteTCB from outside of
2277
- * critical section. If a task deletes itself, prvDeleteTCB is called
2278
- * from prvCheckTasksWaitingTermination which is called from Idle task. */
2279
- if ( pxTCB != pxCurrentTCB )
2280
- {
2281
- prvDeleteTCB ( pxTCB );
2282
- }
2282
+ prvDeleteTCB ( pxTCB );
2283
+ }
2283
2284
2284
- /* Force a reschedule if it is the currently running task that has just
2285
- * been deleted. */
2286
- if ( xSchedulerRunning != pdFALSE )
2285
+ /* Force a reschedule if it is the currently running task that has just
2286
+ * been deleted. */
2287
+ if ( xSchedulerRunning != pdFALSE )
2288
+ {
2289
+ #if ( configNUMBER_OF_CORES == 1 )
2287
2290
{
2288
2291
if ( pxTCB == pxCurrentTCB )
2289
2292
{
2290
2293
configASSERT ( uxSchedulerSuspended == 0 );
2291
- portYIELD_WITHIN_API ();
2294
+ taskYIELD_WITHIN_API ();
2292
2295
}
2293
2296
else
2294
2297
{
2295
2298
mtCOVERAGE_TEST_MARKER ();
2296
2299
}
2297
2300
}
2298
- }
2299
- #else /* #if ( configNUMBER_OF_CORES == 1 ) */
2300
- {
2301
- /* If a running task is not deleting itself, call prvDeleteTCB. If a running
2302
- * task deletes itself, prvDeleteTCB is called from prvCheckTasksWaitingTermination
2303
- * which is called from Idle task. */
2304
- if ( pxTCB -> xTaskRunState == taskTASK_NOT_RUNNING )
2305
- {
2306
- prvDeleteTCB ( pxTCB );
2307
- }
2308
-
2309
- /* Force a reschedule if the task that has just been deleted was running. */
2310
- if ( ( xSchedulerRunning != pdFALSE ) && ( taskTASK_IS_RUNNING ( pxTCB ) == pdTRUE ) )
2301
+ #else /* #if ( configNUMBER_OF_CORES == 1 ) */
2311
2302
{
2312
- if ( pxTCB -> xTaskRunState == ( BaseType_t ) portGET_CORE_ID () )
2313
- {
2314
- configASSERT ( uxSchedulerSuspended == 0 );
2315
- vTaskYieldWithinAPI ();
2316
- }
2317
- else
2303
+ /* It is important to use critical section here because
2304
+ * checking run state of a task must be done inside a
2305
+ * critical section. */
2306
+ taskENTER_CRITICAL ();
2318
2307
{
2319
- prvYieldCore ( pxTCB -> xTaskRunState );
2308
+ if ( taskTASK_IS_RUNNING ( pxTCB ) == pdTRUE )
2309
+ {
2310
+ if ( pxTCB -> xTaskRunState == ( BaseType_t ) portGET_CORE_ID () )
2311
+ {
2312
+ configASSERT ( uxSchedulerSuspended == 0 );
2313
+ taskYIELD_WITHIN_API ();
2314
+ }
2315
+ else
2316
+ {
2317
+ prvYieldCore ( pxTCB -> xTaskRunState );
2318
+ }
2319
+ }
2320
2320
}
2321
+ taskEXIT_CRITICAL ();
2321
2322
}
2322
-
2323
- taskEXIT_CRITICAL ();
2323
+ #endif /* #if ( configNUMBER_OF_CORES == 1 ) */
2324
2324
}
2325
- #endif /* #if ( configNUMBER_OF_CORES == 1 ) */
2326
2325
2327
2326
traceRETURN_vTaskDelete ();
2328
2327
}
0 commit comments