| 1659 | #if ( INCLUDE_vTaskDelete == 1 ) |
| 1660 | |
| 1661 | void vTaskDelete( TaskHandle_t xTaskToDelete ) |
| 1662 | { |
| 1663 | TCB_t * pxTCB; |
| 1664 | TaskRunning_t xTaskRunningOnCore; |
| 1665 | |
| 1666 | taskENTER_CRITICAL(); |
| 1667 | { |
| 1668 | /* If null is passed in here then it is the calling task that is |
| 1669 | * being deleted. */ |
| 1670 | pxTCB = prvGetTCBFromHandle( xTaskToDelete ); |
| 1671 | |
| 1672 | xTaskRunningOnCore = pxTCB->xTaskRunState; |
| 1673 | |
| 1674 | /* Remove task from the ready/delayed list. */ |
| 1675 | if( uxListRemove( &( pxTCB->xStateListItem ) ) == ( UBaseType_t ) 0 ) |
| 1676 | { |
| 1677 | taskRESET_READY_PRIORITY( pxTCB->uxPriority ); |
| 1678 | } |
| 1679 | else |
| 1680 | { |
| 1681 | mtCOVERAGE_TEST_MARKER(); |
| 1682 | } |
| 1683 | |
| 1684 | /* Is the task waiting on an event also? */ |
| 1685 | if( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) != NULL ) |
| 1686 | { |
| 1687 | ( void ) uxListRemove( &( pxTCB->xEventListItem ) ); |
| 1688 | } |
| 1689 | else |
| 1690 | { |
| 1691 | mtCOVERAGE_TEST_MARKER(); |
| 1692 | } |
| 1693 | |
| 1694 | /* Increment the uxTaskNumber also so kernel aware debuggers can |
| 1695 | * detect that the task lists need re-generating. This is done before |
| 1696 | * portPRE_TASK_DELETE_HOOK() as in the Windows port that macro will |
| 1697 | * not return. */ |
| 1698 | uxTaskNumber++; |
| 1699 | |
| 1700 | /* If the task is running (or yielding), we must add it to the |
| 1701 | * termination list so that an idle task can delete it when it is |
| 1702 | * no longer running. */ |
| 1703 | if( xTaskRunningOnCore != taskTASK_NOT_RUNNING ) |
| 1704 | { |
| 1705 | /* A running task is being deleted. This cannot complete within the |
| 1706 | * task itself, as a context switch to another task is required. |
| 1707 | * Place the task in the termination list. The idle task will |
| 1708 | * check the termination list and free up any memory allocated by |
| 1709 | * the scheduler for the TCB and stack of the deleted task. */ |
| 1710 | vListInsertEnd( &xTasksWaitingTermination, &( pxTCB->xStateListItem ) ); |
| 1711 | |
| 1712 | /* Increment the ucTasksDeleted variable so the idle task knows |
| 1713 | * there is a task that has been deleted and that it should therefore |
| 1714 | * check the xTasksWaitingTermination list. */ |
| 1715 | ++uxDeletedTasksWaitingCleanUp; |
| 1716 | |
| 1717 | /* Call the delete hook before portPRE_TASK_DELETE_HOOK() as |
| 1718 | * portPRE_TASK_DELETE_HOOK() does not return in the Win32 port. */ |
no test coverage detected