Skip to content

Commit c028ff4

Browse files
committed
Add ownership check when giving a mutex
Disallow a held mutex from being given by another task, one that did not first take the mutex.
1 parent 78069a7 commit c028ff4

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

queue.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -966,6 +966,20 @@ BaseType_t xQueueGenericSend( QueueHandle_t xQueue,
966966
}
967967
#endif
968968

969+
#if ( configUSE_MUTEXES == 1 )
970+
{
971+
/* If the queue is a mutex and is held, only the owner can give it. */
972+
if( ( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX ) &&
973+
( pxQueue->u.xSemaphore.xMutexHolder != NULL ) &&
974+
( pxQueue->u.xSemaphore.xMutexHolder != xTaskGetCurrentTaskHandle() ) )
975+
{
976+
traceRETURN_xQueueGenericSend( pdFAIL );
977+
978+
return pdFAIL;
979+
}
980+
}
981+
#endif /* configUSE_MUTEXES */
982+
969983
for( ; ; )
970984
{
971985
taskENTER_CRITICAL();

0 commit comments

Comments
 (0)