#define QUEUE_H\r
\r
#ifndef INC_FREERTOS_H\r
- #error "#include FreeRTOS.h" must appear in source files before "#include queue.h"\r
+ #error "include FreeRTOS.h" must appear in source files before "include queue.h"\r
#endif\r
\r
#ifdef __cplusplus\r
signed portBASE_TYPE xQueueCRReceive( xQueueHandle pxQueue, void *pvBuffer, portTickType xTicksToWait );\r
\r
/*\r
- * For internal use only. Use xSemaphoreCreateMutex() or\r
- * xSemaphoreCreateCounting() instead of calling these functions directly.\r
+ * For internal use only. Use xSemaphoreCreateMutex(), \r
+ * xSemaphoreCreateCounting() or xSemaphoreGetMutexHolder() instead of calling \r
+ * these functions directly.\r
*/\r
xQueueHandle xQueueCreateMutex( unsigned char ucQueueType );\r
xQueueHandle xQueueCreateCountingSemaphore( unsigned portBASE_TYPE uxCountValue, unsigned portBASE_TYPE uxInitialCount );\r
+void* xQueueGetMutexHolder( xQueueHandle xSemaphore );\r
\r
/*\r
* For internal use only. Use xSemaphoreTakeMutexRecursive() or\r
#define SEMAPHORE_H\r
\r
#ifndef INC_FREERTOS_H\r
- #error "#include FreeRTOS.h" must appear in source files before "#include semphr.h"\r
+ #error "include FreeRTOS.h" must appear in source files before "include semphr.h"\r
#endif\r
\r
#include "queue.h"\r
* \page vSemaphoreDelete vSemaphoreDelete\r
* \ingroup Semaphores\r
*/\r
-#define vSemaphoreDelete( xSemaphore ) vQueueDelete( ( xQueueHandle ) xSemaphore )\r
+#define vSemaphoreDelete( xSemaphore ) vQueueDelete( ( xQueueHandle ) ( xSemaphore ) )\r
+\r
+/**\r
+ * semphr.h\r
+ * <pre>xTaskHandle xSemaphoreGetMutexHolder( xSemaphoreHandle xMutex );</pre>\r
+ *\r
+ * If xMutex is indeed a mutex type semaphore, return the current mutex holder.\r
+ * If xMutex is not a mutex type semaphore, or the mutex is available (not held\r
+ * by a task), return NULL.\r
+ *\r
+ * Note: This Is is a good way of determining if the calling task is the mutex \r
+ * holder, but not a good way of determining the identity of the mutex holder as\r
+ * the holder may change between the function exiting and the returned value\r
+ * being tested.\r
+ */\r
+#define xSemaphoreGetMutexHolder( xSemaphore ) xQueueGetMutexHolder( ( xSemaphore ) )\r
\r
#endif /* SEMAPHORE_H */\r
\r
void vQueueSetQueueNumber( xQueueHandle pxQueue, unsigned char ucQueueNumber ) PRIVILEGED_FUNCTION;\r
unsigned char ucQueueGetQueueType( xQueueHandle pxQueue ) PRIVILEGED_FUNCTION;\r
portBASE_TYPE xQueueGenericReset( xQueueHandle pxQueue, portBASE_TYPE xNewQueue ) PRIVILEGED_FUNCTION;\r
+xTaskHandle xQueueGetMutexHolder( xQueueHandle xSemaphore ) PRIVILEGED_FUNCTION;\r
\r
/*\r
* Co-routine queue functions differ from task queue functions. Co-routines are\r
size_t xQueueSizeInBytes;\r
xQueueHandle xReturn = NULL;\r
\r
- /* Remove compiler warnings about unused parameters should \r
+ /* Remove compiler warnings about unused parameters should\r
configUSE_TRACE_FACILITY not be set to 1. */\r
( void ) ucQueueType;\r
\r
/* Prevent compiler warnings about unused parameters if\r
configUSE_TRACE_FACILITY does not equal 1. */\r
( void ) ucQueueType;\r
- \r
+\r
/* Allocate the new queue structure. */\r
pxNewQueue = ( xQUEUE * ) pvPortMalloc( sizeof( xQUEUE ) );\r
if( pxNewQueue != NULL )\r
pxNewQueue->uxItemSize = ( unsigned portBASE_TYPE ) 0U;\r
pxNewQueue->xRxLock = queueUNLOCKED;\r
pxNewQueue->xTxLock = queueUNLOCKED;\r
- \r
+\r
#if ( configUSE_TRACE_FACILITY == 1 )\r
{\r
pxNewQueue->ucQueueType = ucQueueType;\r
#endif /* configUSE_MUTEXES */\r
/*-----------------------------------------------------------*/\r
\r
-#if configUSE_RECURSIVE_MUTEXES == 1\r
+#if ( configUSE_MUTEXES == 1 )\r
+\r
+ void* xQueueGetMutexHolder( xQueueHandle xSemaphore )\r
+ {\r
+ void *pxReturn;\r
+\r
+ /* This function is called by xSemaphoreGetMutexHolder(), and should not\r
+ be called directly. Note: This is is a good way of determining if the\r
+ calling task is the mutex holder, but not a good way of determining the\r
+ identity of the mutex holder, as the holder may change between the \r
+ following critical section exiting and the function returning. */\r
+ taskENTER_CRITICAL();\r
+ {\r
+ if( xSemaphore->uxQueueType == queueQUEUE_IS_MUTEX )\r
+ {\r
+ pxReturn = ( void * ) xSemaphore->pxMutexHolder;\r
+ }\r
+ else\r
+ {\r
+ pxReturn = NULL;\r
+ }\r
+ }\r
+ taskEXIT_CRITICAL();\r
+ \r
+ return pxReturn;\r
+ }\r
+\r
+#endif\r
+/*-----------------------------------------------------------*/\r
+\r
+#if ( configUSE_RECURSIVE_MUTEXES == 1 )\r
\r
portBASE_TYPE xQueueGiveMutexRecursive( xQueueHandle pxMutex )\r
{\r