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

Function xQueueGiveMutexRecursive

queue.c:620–668  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

618#if ( configUSE_RECURSIVE_MUTEXES == 1 )
619
620 BaseType_t xQueueGiveMutexRecursive( QueueHandle_t xMutex )
621 {
622 BaseType_t xReturn;
623 Queue_t * const pxMutex = ( Queue_t * ) xMutex;
624
625 configASSERT( pxMutex );
626
627 /* If this is the task that holds the mutex then xMutexHolder will not
628 * change outside of this task. If this task does not hold the mutex then
629 * pxMutexHolder can never coincidentally equal the tasks handle, and as
630 * this is the only condition we are interested in it does not matter if
631 * pxMutexHolder is accessed simultaneously by another task. Therefore no
632 * mutual exclusion is required to test the pxMutexHolder variable. */
633 if( pxMutex->u.xSemaphore.xMutexHolder == xTaskGetCurrentTaskHandle() )
634 {
635 traceGIVE_MUTEX_RECURSIVE( pxMutex );
636
637 /* uxRecursiveCallCount cannot be zero if xMutexHolder is equal to
638 * the task handle, therefore no underflow check is required. Also,
639 * uxRecursiveCallCount is only modified by the mutex holder, and as
640 * there can only be one, no mutual exclusion is required to modify the
641 * uxRecursiveCallCount member. */
642 ( pxMutex->u.xSemaphore.uxRecursiveCallCount )--;
643
644 /* Has the recursive call count unwound to 0? */
645 if( pxMutex->u.xSemaphore.uxRecursiveCallCount == ( UBaseType_t ) 0 )
646 {
647 /* Return the mutex. This will automatically unblock any other
648 * task that might be waiting to access the mutex. */
649 ( void ) xQueueGenericSend( pxMutex, NULL, queueMUTEX_GIVE_BLOCK_TIME, queueSEND_TO_BACK );
650 }
651 else
652 {
653 mtCOVERAGE_TEST_MARKER();
654 }
655
656 xReturn = pdPASS;
657 }
658 else
659 {
660 /* The mutex cannot be given because the calling task is not the
661 * holder. */
662 xReturn = pdFAIL;
663
664 traceGIVE_MUTEX_RECURSIVE_FAILED( pxMutex );
665 }
666
667 return xReturn;
668 }
669
670#endif /* configUSE_RECURSIVE_MUTEXES */
671/*-----------------------------------------------------------*/

Callers 1

Calls 2

xQueueGenericSendFunction · 0.85

Tested by

no test coverage detected