MCPcopy Create free account
hub / github.com/FreeRTOS/FreeRTOS-Kernel / xTaskPriorityDisinherit

Function xTaskPriorityDisinherit

tasks.c:5064–5137  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5062#if ( configUSE_MUTEXES == 1 )
5063
5064 BaseType_t xTaskPriorityDisinherit( TaskHandle_t const pxMutexHolder )
5065 {
5066 TCB_t * const pxTCB = pxMutexHolder;
5067 BaseType_t xReturn = pdFALSE;
5068
5069 if( pxMutexHolder != NULL )
5070 {
5071 /* A task can only have an inherited priority if it holds the mutex.
5072 * If the mutex is held by a task then it cannot be given from an
5073 * interrupt, and if a mutex is given by the holding task then it must
5074 * be the running state task. */
5075 configASSERT( pxTCB == pxCurrentTCB );
5076 configASSERT( pxTCB->uxMutexesHeld );
5077 ( pxTCB->uxMutexesHeld )--;
5078
5079 /* Has the holder of the mutex inherited the priority of another
5080 * task? */
5081 if( pxTCB->uxPriority != pxTCB->uxBasePriority )
5082 {
5083 /* Only disinherit if no other mutexes are held. */
5084 if( pxTCB->uxMutexesHeld == ( UBaseType_t ) 0 )
5085 {
5086 /* A task can only have an inherited priority if it holds
5087 * the mutex. If the mutex is held by a task then it cannot be
5088 * given from an interrupt, and if a mutex is given by the
5089 * holding task then it must be the running state task. Remove
5090 * the holding task from the ready list. */
5091 if( uxListRemove( &( pxTCB->xStateListItem ) ) == ( UBaseType_t ) 0 )
5092 {
5093 portRESET_READY_PRIORITY( pxTCB->uxPriority, uxTopReadyPriority );
5094 }
5095 else
5096 {
5097 mtCOVERAGE_TEST_MARKER();
5098 }
5099
5100 /* Disinherit the priority before adding the task into the
5101 * new ready list. */
5102 traceTASK_PRIORITY_DISINHERIT( pxTCB, pxTCB->uxBasePriority );
5103 pxTCB->uxPriority = pxTCB->uxBasePriority;
5104
5105 /* Reset the event list item value. It cannot be in use for
5106 * any other purpose if this task is running, and it must be
5107 * running to give back the mutex. */
5108 listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), ( TickType_t ) configMAX_PRIORITIES - ( TickType_t ) pxTCB->uxPriority ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */
5109 prvAddTaskToReadyList( pxTCB );
5110
5111 /* Return true to indicate that a context switch is required.
5112 * This is only actually required in the corner case whereby
5113 * multiple mutexes were held and the mutexes were given back
5114 * in an order different to that in which they were taken.
5115 * If a context switch did not occur when the first mutex was
5116 * returned, even if a task was waiting on it, then a context
5117 * switch should occur when the last mutex is returned whether
5118 * a task is waiting on it or not. */
5119 xReturn = pdTRUE;
5120 }
5121 else

Callers 1

prvCopyDataToQueueFunction · 0.85

Calls 1

uxListRemoveFunction · 0.85

Tested by

no test coverage detected