]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Source/queue.c
Update QueueOverwrite.c to include a call to xQueuePeekFromISR().
[freertos] / FreeRTOS / Source / queue.c
index db21c3c071dabfebd7e061ff66ba94cacc69d88c..b9024d5354da203f0b1c4920fc1e882846f9f82f 100644 (file)
@@ -1,7 +1,7 @@
 /*\r
-    FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd.\r
+    FreeRTOS V7.4.2 - Copyright (C) 2013 Real Time Engineers Ltd.\r
 \r
-    FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME.  PLEASE VISIT \r
+    FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME.  PLEASE VISIT\r
     http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
 \r
     ***************************************************************************\r
     FreeRTOS is free software; you can redistribute it and/or modify it under\r
     the terms of the GNU General Public License (version 2) as published by the\r
     Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
-    >>>NOTE<<< The modification to the GPL is included to allow you to\r
+\r
+    >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to\r
     distribute a combined work that includes FreeRTOS without being obliged to\r
     provide the source code for proprietary components outside of the FreeRTOS\r
-    kernel.  FreeRTOS is distributed in the hope that it will be useful, but\r
-    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
-    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
-    more details. You should have received a copy of the GNU General Public\r
-    License and the FreeRTOS license exception along with FreeRTOS; if not it\r
-    can be viewed here: http://www.freertos.org/a00114.html and also obtained\r
-    by writing to Richard Barry, contact details for whom are available on the\r
-    FreeRTOS WEB site.\r
+    kernel.\r
+\r
+    FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
+    WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
+    FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more\r
+    details. You should have received a copy of the GNU General Public License\r
+    and the FreeRTOS license exception along with FreeRTOS; if not it can be\r
+    viewed here: http://www.freertos.org/a00114.html and also obtained by\r
+    writing to Real Time Engineers Ltd., contact details for whom are available\r
+    on the FreeRTOS WEB site.\r
 \r
     1 tab == 4 spaces!\r
-    \r
+\r
     ***************************************************************************\r
      *                                                                       *\r
      *    Having a problem?  Start by reading the FAQ "My application does   *\r
      *                                                                       *\r
     ***************************************************************************\r
 \r
-    \r
-    http://www.FreeRTOS.org - Documentation, training, latest versions, license \r
-    and contact details.  \r
-    \r
+\r
+    http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
+    license and Real Time Engineers Ltd. contact details.\r
+\r
     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
-    including FreeRTOS+Trace - an indispensable productivity tool.\r
+    including FreeRTOS+Trace - an indispensable productivity tool, and our new\r
+    fully thread aware and reentrant UDP/IP stack.\r
+\r
+    http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
+    Integrity Systems, who sell the code with commercial support,\r
+    indemnification and middleware, under the OpenRTOS brand.\r
 \r
-    Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell \r
-    the code with commercial support, indemnification, and middleware, under \r
-    the OpenRTOS brand: http://www.OpenRTOS.com.  High Integrity Systems also\r
-    provide a safety engineered and independently SIL3 certified version under \r
-    the SafeRTOS brand: http://www.SafeRTOS.com.\r
+    http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
+    engineered and independently SIL3 certified version for use in safety and\r
+    mission critical applications that require provable dependability.\r
 */\r
 \r
 #include <stdlib.h>\r
@@ -76,6 +82,7 @@ task.h is included from an application file. */
 \r
 #include "FreeRTOS.h"\r
 #include "task.h"\r
+#include "queue.h"\r
 \r
 #if ( configUSE_CO_ROUTINES == 1 )\r
        #include "croutine.h"\r
@@ -89,29 +96,27 @@ task.h is included from an application file. */
 \r
 #define queueERRONEOUS_UNBLOCK                 ( -1 )\r
 \r
-/* For internal use only. */\r
-#define        queueSEND_TO_BACK                               ( 0 )\r
-#define        queueSEND_TO_FRONT                              ( 1 )\r
-\r
-/* Effectively make a union out of the xQUEUE structure. */\r
+/* When the xQUEUE structure is used to represent a base queue its pcHead and\r
+pcTail members are used as pointers into the queue storage area.  When the\r
+xQUEUE structure is used to represent a mutex pcHead and pcTail pointers are\r
+not necessary, and the pcHead pointer is set to NULL to indicate that the\r
+pcTail pointer actually points to the mutex holder (if any).  Map alternative\r
+names to the pcHead and pcTail structure members to ensure the readability of\r
+the code is maintained despite this dual use of two structure members.  An\r
+alternative implementation would be to use a union, but use of a union is\r
+against the coding standard (although an exception to the standard has been\r
+permitted where the dual use also significantly changes the type of the\r
+structure member). */\r
 #define pxMutexHolder                                  pcTail\r
 #define uxQueueType                                            pcHead\r
-#define uxRecursiveCallCount                   pcReadFrom\r
 #define queueQUEUE_IS_MUTEX                            NULL\r
 \r
-/* Semaphores do not actually store or copy data, so have an items size of\r
+/* Semaphores do not actually store or copy data, so have an item size of\r
 zero. */\r
 #define queueSEMAPHORE_QUEUE_ITEM_LENGTH ( ( unsigned portBASE_TYPE ) 0 )\r
 #define queueDONT_BLOCK                                         ( ( portTickType ) 0U )\r
 #define queueMUTEX_GIVE_BLOCK_TIME              ( ( portTickType ) 0U )\r
 \r
-/* These definitions *must* match those in queue.h. */\r
-#define queueQUEUE_TYPE_BASE                           ( 0U )\r
-#define queueQUEUE_TYPE_MUTEX                          ( 1U )\r
-#define queueQUEUE_TYPE_COUNTING_SEMAPHORE     ( 2U )\r
-#define queueQUEUE_TYPE_BINARY_SEMAPHORE       ( 3U )\r
-#define queueQUEUE_TYPE_RECURSIVE_MUTEX                ( 4U )\r
-#define queueQUEUE_TYPE_SET                                    ( 5U )\r
 \r
 /*\r
  * Definition of the queue used by the scheduler.\r
@@ -123,7 +128,12 @@ typedef struct QueueDefinition
        signed char *pcTail;                                    /*< Points to the byte at the end of the queue storage area.  Once more byte is allocated than necessary to store the queue items, this is used as a marker. */\r
 \r
        signed char *pcWriteTo;                                 /*< Points to the free next place in the storage area. */\r
-       signed char *pcReadFrom;                                /*< Points to the last place that a queued item was read from. */\r
+\r
+       union                                                                   /* Use of a union is an exception to the coding standard to ensure two mutually exclusive structure members don't appear simultaneously (wasting RAM). */\r
+       {\r
+               signed char *pcReadFrom;                        /*< Points to the last place that a queued item was read from when the structure is used as a queue. */\r
+               unsigned portBASE_TYPE uxRecursiveCallCount;/*< Maintains a count of the numebr of times a recursive mutex has been recursively 'taken' when the structure is used as a mutex. */\r
+       } u;\r
 \r
        xList xTasksWaitingToSend;                              /*< List of tasks that are blocked waiting to post onto this queue.  Stored in priority order. */\r
        xList xTasksWaitingToReceive;                   /*< List of tasks that are blocked waiting to read from this queue.  Stored in priority order. */\r
@@ -147,59 +157,6 @@ typedef struct QueueDefinition
 } xQUEUE;\r
 /*-----------------------------------------------------------*/\r
 \r
-/*\r
- * Inside this file xQueueHandle is a pointer to a xQUEUE structure.\r
- * To keep the definition private the API header file defines it as a\r
- * pointer to void.\r
- */\r
-typedef xQUEUE * xQueueHandle;\r
-typedef xQUEUE * xQueueSetHandle;\r
-\r
-/*\r
- * In order to implement strict data hiding, the queue.h header file defines \r
- * xQueueHandle and xQueueSetHandle as pointers to void.  In this file\r
- * xQueueHandle and xQueueSetHandle are defined as pointers to xQUEUE objects.\r
- * Therefore the queue.h header file cannot be included in this source file,\r
- * and the function prototypes are provided directly.\r
- */\r
-xQueueHandle xQueueGenericCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBASE_TYPE uxItemSize, unsigned char ucQueueType ) PRIVILEGED_FUNCTION;\r
-signed portBASE_TYPE xQueueGenericSend( xQueueHandle pxQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition ) PRIVILEGED_FUNCTION;\r
-unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle pxQueue ) PRIVILEGED_FUNCTION;\r
-void vQueueDelete( xQueueHandle xQueue ) PRIVILEGED_FUNCTION;\r
-signed portBASE_TYPE xQueueGenericSendFromISR( xQueueHandle pxQueue, const void * const pvItemToQueue, signed portBASE_TYPE *pxHigherPriorityTaskWoken, portBASE_TYPE xCopyPosition ) PRIVILEGED_FUNCTION;\r
-signed portBASE_TYPE xQueueGenericReceive( xQueueHandle pxQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking ) PRIVILEGED_FUNCTION;\r
-signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle pxQueue, void * const pvBuffer, signed portBASE_TYPE *pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;\r
-xQueueHandle xQueueCreateMutex( unsigned char ucQueueType ) PRIVILEGED_FUNCTION;\r
-xQueueHandle xQueueCreateCountingSemaphore( unsigned portBASE_TYPE uxCountValue, unsigned portBASE_TYPE uxInitialCount ) PRIVILEGED_FUNCTION;\r
-portBASE_TYPE xQueueTakeMutexRecursive( xQueueHandle xMutex, portTickType xBlockTime ) PRIVILEGED_FUNCTION;\r
-portBASE_TYPE xQueueGiveMutexRecursive( xQueueHandle xMutex ) PRIVILEGED_FUNCTION;\r
-signed portBASE_TYPE xQueueAltGenericSend( xQueueHandle pxQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition ) PRIVILEGED_FUNCTION;\r
-signed portBASE_TYPE xQueueAltGenericReceive( xQueueHandle pxQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking ) PRIVILEGED_FUNCTION;\r
-signed portBASE_TYPE xQueueIsQueueEmptyFromISR( const xQueueHandle pxQueue ) PRIVILEGED_FUNCTION;\r
-signed portBASE_TYPE xQueueIsQueueFullFromISR( const xQueueHandle pxQueue ) PRIVILEGED_FUNCTION;\r
-unsigned portBASE_TYPE uxQueueMessagesWaitingFromISR( const xQueueHandle pxQueue ) PRIVILEGED_FUNCTION;\r
-void vQueueWaitForMessageRestricted( xQueueHandle pxQueue, portTickType xTicksToWait ) PRIVILEGED_FUNCTION;\r
-unsigned char ucQueueGetQueueNumber( xQueueHandle pxQueue ) PRIVILEGED_FUNCTION;\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
-xQueueSetHandle xQueueSetCreate( unsigned portBASE_TYPE uxEventQueueLength ) PRIVILEGED_FUNCTION;\r
-xQueueHandle xQueueReadMultiple( xQueueSetHandle xQueueSet, portTickType xBlockTimeTicks ) PRIVILEGED_FUNCTION;\r
-portBASE_TYPE xQueueAddToQueueSet( xQueueHandle xQueue, xQueueSetHandle xQueueSet ) PRIVILEGED_FUNCTION;\r
-portBASE_TYPE xQueueRemoveFromQueueSet( xQueueSetHandle xQueueSet, xQueueHandle xQueue ) PRIVILEGED_FUNCTION;\r
-\r
-/*\r
- * Co-routine queue functions differ from task queue functions.  Co-routines are\r
- * an optional component.\r
- */\r
-#if ( configUSE_CO_ROUTINES == 1 )\r
-       signed portBASE_TYPE xQueueCRSendFromISR( xQueueHandle pxQueue, const void *pvItemToQueue, signed portBASE_TYPE xCoRoutinePreviouslyWoken ) PRIVILEGED_FUNCTION;\r
-       signed portBASE_TYPE xQueueCRReceiveFromISR( xQueueHandle pxQueue, void *pvBuffer, signed portBASE_TYPE *pxTaskWoken ) PRIVILEGED_FUNCTION;\r
-       signed portBASE_TYPE xQueueCRSend( xQueueHandle pxQueue, const void *pvItemToQueue, portTickType xTicksToWait ) PRIVILEGED_FUNCTION;\r
-       signed portBASE_TYPE xQueueCRReceive( xQueueHandle pxQueue, void *pvBuffer, portTickType xTicksToWait ) PRIVILEGED_FUNCTION;\r
-#endif\r
-\r
 /*\r
  * The queue registry is just a means for kernel aware debuggers to locate\r
  * queue structures.  It has no other purpose so is an optional component.\r
@@ -220,11 +177,7 @@ portBASE_TYPE xQueueRemoveFromQueueSet( xQueueSetHandle xQueueSet, xQueueHandle
        array position being vacant. */\r
        xQueueRegistryItem xQueueRegistry[ configQUEUE_REGISTRY_SIZE ];\r
 \r
-       /* Removes a queue from the registry by simply setting the pcQueueName\r
-       member to NULL. */\r
-       static void vQueueUnregisterQueue( xQueueHandle xQueue ) PRIVILEGED_FUNCTION;\r
-       void vQueueAddToRegistry( xQueueHandle xQueue, signed char *pcQueueName ) PRIVILEGED_FUNCTION;\r
-#endif\r
+#endif /* configQUEUE_REGISTRY_SIZE */\r
 \r
 /*\r
  * Unlocks a queue locked by a call to prvLockQueue.  Locking a queue does not\r
@@ -234,21 +187,21 @@ portBASE_TYPE xQueueRemoveFromQueueSet( xQueueSetHandle xQueueSet, xQueueHandle
  * to indicate that a task may require unblocking.  When the queue in unlocked\r
  * these lock counts are inspected, and the appropriate action taken.\r
  */\r
-static void prvUnlockQueue( xQueueHandle pxQueue ) PRIVILEGED_FUNCTION;\r
+static void prvUnlockQueue( xQUEUE *pxQueue ) PRIVILEGED_FUNCTION;\r
 \r
 /*\r
  * Uses a critical section to determine if there is any data in a queue.\r
  *\r
  * @return pdTRUE if the queue contains no items, otherwise pdFALSE.\r
  */\r
-static signed portBASE_TYPE prvIsQueueEmpty( const xQueueHandle pxQueue ) PRIVILEGED_FUNCTION;\r
+static signed portBASE_TYPE prvIsQueueEmpty( const xQUEUE *pxQueue ) PRIVILEGED_FUNCTION;\r
 \r
 /*\r
  * Uses a critical section to determine if there is any space in a queue.\r
  *\r
  * @return pdTRUE if there is no space, otherwise pdFALSE;\r
  */\r
-static signed portBASE_TYPE prvIsQueueFull( const xQueueHandle pxQueue ) PRIVILEGED_FUNCTION;\r
+static signed portBASE_TYPE prvIsQueueFull( const xQUEUE *pxQueue ) PRIVILEGED_FUNCTION;\r
 \r
 /*\r
  * Copies an item into the queue, either at the front of the queue or the\r
@@ -266,7 +219,7 @@ static void prvCopyDataFromQueue( xQUEUE * const pxQueue, const void *pvBuffer )
         * Checks to see if a queue is a member of a queue set, and if so, notifies\r
         * the queue set that the queue contains data.\r
         */\r
-       static portBASE_TYPE prvCheckForMembershipOfQueueSet( xQUEUE *pxQueue, portBASE_TYPE xCopyPosition );\r
+       static portBASE_TYPE prvNotifyQueueSetContainer( xQUEUE *pxQueue, portBASE_TYPE xCopyPosition ) PRIVILEGED_FUNCTION;\r
 #endif\r
 \r
 /*-----------------------------------------------------------*/\r
@@ -290,8 +243,11 @@ static void prvCopyDataFromQueue( xQUEUE * const pxQueue, const void *pvBuffer )
        taskEXIT_CRITICAL()\r
 /*-----------------------------------------------------------*/\r
 \r
-portBASE_TYPE xQueueGenericReset( xQueueHandle pxQueue, portBASE_TYPE xNewQueue )\r
+portBASE_TYPE xQueueGenericReset( xQueueHandle xQueue, portBASE_TYPE xNewQueue )\r
 {\r
+xQUEUE *pxQueue;\r
+\r
+       pxQueue = ( xQUEUE * ) xQueue;\r
        configASSERT( pxQueue );\r
 \r
        taskENTER_CRITICAL();\r
@@ -299,7 +255,7 @@ portBASE_TYPE xQueueGenericReset( xQueueHandle pxQueue, portBASE_TYPE xNewQueue
                pxQueue->pcTail = pxQueue->pcHead + ( pxQueue->uxLength * pxQueue->uxItemSize );\r
                pxQueue->uxMessagesWaiting = ( unsigned portBASE_TYPE ) 0U;\r
                pxQueue->pcWriteTo = pxQueue->pcHead;\r
-               pxQueue->pcReadFrom = pxQueue->pcHead + ( ( pxQueue->uxLength - ( unsigned portBASE_TYPE ) 1U ) * pxQueue->uxItemSize );\r
+               pxQueue->u.pcReadFrom = pxQueue->pcHead + ( ( pxQueue->uxLength - ( unsigned portBASE_TYPE ) 1U ) * pxQueue->uxItemSize );\r
                pxQueue->xRxLock = queueUNLOCKED;\r
                pxQueue->xTxLock = queueUNLOCKED;\r
 \r
@@ -361,7 +317,7 @@ xQueueHandle xReturn = NULL;
                                pxNewQueue->uxLength = uxQueueLength;\r
                                pxNewQueue->uxItemSize = uxItemSize;\r
                                xQueueGenericReset( pxNewQueue, pdTRUE );\r
-                               \r
+\r
                                #if ( configUSE_TRACE_FACILITY == 1 )\r
                                {\r
                                        pxNewQueue->ucQueueType = ucQueueType;\r
@@ -412,7 +368,7 @@ xQueueHandle xReturn = NULL;
                        /* Queues used as a mutex no data is actually copied into or out\r
                        of the queue. */\r
                        pxNewQueue->pcWriteTo = NULL;\r
-                       pxNewQueue->pcReadFrom = NULL;\r
+                       pxNewQueue->u.pcReadFrom = NULL;\r
 \r
                        /* Each mutex has a length of 1 (like a binary semaphore) and\r
                        an item size of 0 as nothing is actually copied into or out\r
@@ -469,9 +425,9 @@ xQueueHandle xReturn = NULL;
                following critical section exiting and the function returning. */\r
                taskENTER_CRITICAL();\r
                {\r
-                       if( xSemaphore->uxQueueType == queueQUEUE_IS_MUTEX )\r
+                       if( ( ( xQUEUE * ) xSemaphore )->uxQueueType == queueQUEUE_IS_MUTEX )\r
                        {\r
-                               pxReturn = ( void * ) xSemaphore->pxMutexHolder;\r
+                               pxReturn = ( void * ) ( ( xQUEUE * ) xSemaphore )->pxMutexHolder;\r
                        }\r
                        else\r
                        {\r
@@ -488,10 +444,12 @@ xQueueHandle xReturn = NULL;
 \r
 #if ( configUSE_RECURSIVE_MUTEXES == 1 )\r
 \r
-       portBASE_TYPE xQueueGiveMutexRecursive( xQueueHandle pxMutex )\r
+       portBASE_TYPE xQueueGiveMutexRecursive( xQueueHandle xMutex )\r
        {\r
        portBASE_TYPE xReturn;\r
+       xQUEUE *pxMutex;\r
 \r
+               pxMutex = ( xQUEUE * ) xMutex;\r
                configASSERT( pxMutex );\r
 \r
                /* If this is the task that holds the mutex then pxMutexHolder will not\r
@@ -500,7 +458,7 @@ xQueueHandle xReturn = NULL;
                this is the only condition we are interested in it does not matter if\r
                pxMutexHolder is accessed simultaneously by another task.  Therefore no\r
                mutual exclusion is required to test the pxMutexHolder variable. */\r
-               if( pxMutex->pxMutexHolder == xTaskGetCurrentTaskHandle() )\r
+               if( pxMutex->pxMutexHolder == ( void * ) xTaskGetCurrentTaskHandle() )\r
                {\r
                        traceGIVE_MUTEX_RECURSIVE( pxMutex );\r
 \r
@@ -509,10 +467,10 @@ xQueueHandle xReturn = NULL;
                        uxRecursiveCallCount is only modified by the mutex holder, and as\r
                        there can only be one, no mutual exclusion is required to modify the\r
                        uxRecursiveCallCount member. */\r
-                       ( pxMutex->uxRecursiveCallCount )--;\r
+                       ( pxMutex->u.uxRecursiveCallCount )--;\r
 \r
                        /* Have we unwound the call count? */\r
-                       if( pxMutex->uxRecursiveCallCount == 0 )\r
+                       if( pxMutex->u.uxRecursiveCallCount == 0 )\r
                        {\r
                                /* Return the mutex.  This will automatically unblock any other\r
                                task that might be waiting to access the mutex. */\r
@@ -537,10 +495,12 @@ xQueueHandle xReturn = NULL;
 \r
 #if ( configUSE_RECURSIVE_MUTEXES == 1 )\r
 \r
-       portBASE_TYPE xQueueTakeMutexRecursive( xQueueHandle pxMutex, portTickType xBlockTime )\r
+       portBASE_TYPE xQueueTakeMutexRecursive( xQueueHandle xMutex, portTickType xBlockTime )\r
        {\r
        portBASE_TYPE xReturn;\r
+       xQUEUE *pxMutex;\r
 \r
+               pxMutex = ( xQUEUE * ) xMutex;\r
                configASSERT( pxMutex );\r
 \r
                /* Comments regarding mutual exclusion as per those within\r
@@ -548,9 +508,9 @@ xQueueHandle xReturn = NULL;
 \r
                traceTAKE_MUTEX_RECURSIVE( pxMutex );\r
 \r
-               if( pxMutex->pxMutexHolder == xTaskGetCurrentTaskHandle() )\r
+               if( pxMutex->pxMutexHolder == ( void * )  xTaskGetCurrentTaskHandle() )\r
                {\r
-                       ( pxMutex->uxRecursiveCallCount )++;\r
+                       ( pxMutex->u.uxRecursiveCallCount )++;\r
                        xReturn = pdPASS;\r
                }\r
                else\r
@@ -561,7 +521,7 @@ xQueueHandle xReturn = NULL;
                        we may have blocked to reach here. */\r
                        if( xReturn == pdPASS )\r
                        {\r
-                               ( pxMutex->uxRecursiveCallCount )++;\r
+                               ( pxMutex->u.uxRecursiveCallCount )++;\r
                        }\r
                        else\r
                        {\r
@@ -579,13 +539,13 @@ xQueueHandle xReturn = NULL;
 \r
        xQueueHandle xQueueCreateCountingSemaphore( unsigned portBASE_TYPE uxCountValue, unsigned portBASE_TYPE uxInitialCount )\r
        {\r
-       xQueueHandle pxHandle;\r
+       xQueueHandle xHandle;\r
 \r
-               pxHandle = xQueueGenericCreate( ( unsigned portBASE_TYPE ) uxCountValue, queueSEMAPHORE_QUEUE_ITEM_LENGTH, queueQUEUE_TYPE_COUNTING_SEMAPHORE );\r
+               xHandle = xQueueGenericCreate( ( unsigned portBASE_TYPE ) uxCountValue, queueSEMAPHORE_QUEUE_ITEM_LENGTH, queueQUEUE_TYPE_COUNTING_SEMAPHORE );\r
 \r
-               if( pxHandle != NULL )\r
+               if( xHandle != NULL )\r
                {\r
-                       pxHandle->uxMessagesWaiting = uxInitialCount;\r
+                       ( ( xQUEUE * ) xHandle )->uxMessagesWaiting = uxInitialCount;\r
 \r
                        traceCREATE_COUNTING_SEMAPHORE();\r
                }\r
@@ -594,20 +554,23 @@ xQueueHandle xReturn = NULL;
                        traceCREATE_COUNTING_SEMAPHORE_FAILED();\r
                }\r
 \r
-               configASSERT( pxHandle );\r
-               return pxHandle;\r
+               configASSERT( xHandle );\r
+               return xHandle;\r
        }\r
 \r
 #endif /* configUSE_COUNTING_SEMAPHORES */\r
 /*-----------------------------------------------------------*/\r
 \r
-signed portBASE_TYPE xQueueGenericSend( xQueueHandle pxQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition )\r
+signed portBASE_TYPE xQueueGenericSend( xQueueHandle xQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition )\r
 {\r
 signed portBASE_TYPE xEntryTimeSet = pdFALSE;\r
 xTimeOutType xTimeOut;\r
+xQUEUE *pxQueue;\r
 \r
+       pxQueue = ( xQUEUE * ) xQueue;\r
        configASSERT( pxQueue );\r
        configASSERT( !( ( pvItemToQueue == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) );\r
+       configASSERT( !( ( xCopyPosition == queueOVERWRITE ) && ( pxQueue->uxLength != 1 ) ) );\r
 \r
        /* This function relaxes the coding standard somewhat to allow return\r
        statements within the function itself.  This is done in the interest\r
@@ -616,40 +579,61 @@ xTimeOutType xTimeOut;
        {\r
                taskENTER_CRITICAL();\r
                {\r
-                       /* Is there room on the queue now?  To be running we must be\r
-                       the highest priority task wanting to access the queue. */\r
-                       if( pxQueue->uxMessagesWaiting < pxQueue->uxLength )\r
+                       /* Is there room on the queue now?  The running task must be\r
+                       the highest priority task wanting to access the queue.  If\r
+                       the head item in the queue is to be overwritten then it does\r
+                       not matter if the queue is full. */\r
+                       if( ( pxQueue->uxMessagesWaiting < pxQueue->uxLength ) || ( xCopyPosition == queueOVERWRITE ) )\r
                        {\r
                                traceQUEUE_SEND( pxQueue );\r
                                prvCopyDataToQueue( pxQueue, pvItemToQueue, xCopyPosition );\r
 \r
-                               /* If there was a task waiting for data to arrive on the\r
-                               queue then unblock it now. */\r
-                               if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\r
+                               #if ( configUSE_QUEUE_SETS == 1 )\r
                                {\r
-                                       if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) == pdTRUE )\r
+                                       if( pxQueue->pxQueueSetContainer != NULL )\r
                                        {\r
-                                               /* The unblocked task has a priority higher than\r
-                                               our own so yield immediately.  Yes it is ok to do\r
-                                               this from within the critical section - the kernel\r
-                                               takes care of that. */\r
-                                               portYIELD_WITHIN_API();\r
+                                               if( prvNotifyQueueSetContainer( pxQueue, xCopyPosition ) == pdTRUE )\r
+                                               {\r
+                                                       /* The queue is a member of a queue set, and posting\r
+                                                       to the queue set caused a higher priority task to\r
+                                                       unblock. A context switch is required. */\r
+                                                       portYIELD_WITHIN_API();\r
+                                               }\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               /* If there was a task waiting for data to arrive on the\r
+                                               queue then unblock it now. */\r
+                                               if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\r
+                                               {\r
+                                                       if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) == pdTRUE )\r
+                                                       {\r
+                                                               /* The unblocked task has a priority higher than\r
+                                                               our own so yield immediately.  Yes it is ok to\r
+                                                               do this from within the critical section - the\r
+                                                               kernel takes care of that. */\r
+                                                               portYIELD_WITHIN_API();\r
+                                                       }\r
+                                               }\r
                                        }\r
                                }\r
-                               else\r
+                               #else /* configUSE_QUEUE_SETS */\r
                                {\r
-                                       #if ( configUSE_QUEUE_SETS == 1 )\r
+                                       /* If there was a task waiting for data to arrive on the\r
+                                       queue then unblock it now. */\r
+                                       if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\r
                                        {\r
-                                               if( prvCheckForMembershipOfQueueSet( pxQueue, xCopyPosition ) == pdTRUE )\r
+                                               if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) == pdTRUE )\r
                                                {\r
-                                                       /* The queue is a member of a queue set, and posting to\r
-                                                       the queue set caused a higher priority task to unblock.\r
-                                                       A context switch is required. */\r
+                                                       /* The unblocked task has a priority higher than\r
+                                                       our own so yield immediately.  Yes it is ok to do\r
+                                                       this from within the critical section - the kernel\r
+                                                       takes care of that. */\r
                                                        portYIELD_WITHIN_API();\r
                                                }\r
                                        }\r
-                                       #endif /* configUSE_QUEUE_SETS */\r
                                }\r
+                               #endif /* configUSE_QUEUE_SETS */\r
 \r
                                taskEXIT_CRITICAL();\r
 \r
@@ -736,11 +720,13 @@ xTimeOutType xTimeOut;
 \r
 #if ( configUSE_ALTERNATIVE_API == 1 )\r
 \r
-       signed portBASE_TYPE xQueueAltGenericSend( xQueueHandle pxQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition )\r
+       signed portBASE_TYPE xQueueAltGenericSend( xQueueHandle xQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition )\r
        {\r
        signed portBASE_TYPE xEntryTimeSet = pdFALSE;\r
        xTimeOutType xTimeOut;\r
+       xQUEUE *pxQueue;\r
 \r
+               pxQueue = ( xQUEUE * ) xQueue;\r
                configASSERT( pxQueue );\r
                configASSERT( !( ( pvItemToQueue == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) );\r
 \r
@@ -813,12 +799,14 @@ xTimeOutType xTimeOut;
 \r
 #if ( configUSE_ALTERNATIVE_API == 1 )\r
 \r
-       signed portBASE_TYPE xQueueAltGenericReceive( xQueueHandle pxQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking )\r
+       signed portBASE_TYPE xQueueAltGenericReceive( xQueueHandle xQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking )\r
        {\r
        signed portBASE_TYPE xEntryTimeSet = pdFALSE;\r
        xTimeOutType xTimeOut;\r
        signed char *pcOriginalReadPosition;\r
+       xQUEUE *pxQueue;\r
 \r
+               pxQueue = ( xQUEUE * ) xQueue;\r
                configASSERT( pxQueue );\r
                configASSERT( !( ( pvBuffer == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) );\r
 \r
@@ -829,7 +817,7 @@ xTimeOutType xTimeOut;
                                if( pxQueue->uxMessagesWaiting > ( unsigned portBASE_TYPE ) 0 )\r
                                {\r
                                        /* Remember our read position in case we are just peeking. */\r
-                                       pcOriginalReadPosition = pxQueue->pcReadFrom;\r
+                                       pcOriginalReadPosition = pxQueue->u.pcReadFrom;\r
 \r
                                        prvCopyDataFromQueue( pxQueue, pvBuffer );\r
 \r
@@ -846,7 +834,7 @@ xTimeOutType xTimeOut;
                                                        {\r
                                                                /* Record the information required to implement\r
                                                                priority inheritance should it become necessary. */\r
-                                                               pxQueue->pxMutexHolder = xTaskGetCurrentTaskHandle();\r
+                                                               pxQueue->pxMutexHolder = ( void * ) xTaskGetCurrentTaskHandle();\r
                                                        }\r
                                                }\r
                                                #endif\r
@@ -865,7 +853,7 @@ xTimeOutType xTimeOut;
 \r
                                                /* We are not removing the data, so reset our read\r
                                                pointer. */\r
-                                               pxQueue->pcReadFrom = pcOriginalReadPosition;\r
+                                               pxQueue->u.pcReadFrom = pcOriginalReadPosition;\r
 \r
                                                /* The data is being left in the queue, so see if there are\r
                                                any other tasks waiting for the data. */\r
@@ -942,13 +930,16 @@ xTimeOutType xTimeOut;
 #endif /* configUSE_ALTERNATIVE_API */\r
 /*-----------------------------------------------------------*/\r
 \r
-signed portBASE_TYPE xQueueGenericSendFromISR( xQueueHandle pxQueue, const void * const pvItemToQueue, signed portBASE_TYPE *pxHigherPriorityTaskWoken, portBASE_TYPE xCopyPosition )\r
+signed portBASE_TYPE xQueueGenericSendFromISR( xQueueHandle xQueue, const void * const pvItemToQueue, signed portBASE_TYPE *pxHigherPriorityTaskWoken, portBASE_TYPE xCopyPosition )\r
 {\r
 signed portBASE_TYPE xReturn;\r
 unsigned portBASE_TYPE uxSavedInterruptStatus;\r
+xQUEUE *pxQueue;\r
 \r
+       pxQueue = ( xQUEUE * ) xQueue;\r
        configASSERT( pxQueue );\r
        configASSERT( !( ( pvItemToQueue == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) );\r
+       configASSERT( !( ( xCopyPosition == queueOVERWRITE ) && ( pxQueue->uxLength != 1 ) ) );\r
 \r
        /* Similar to xQueueGenericSend, except we don't block if there is no room\r
        in the queue.  Also we don't directly wake a task that was blocked on a\r
@@ -957,7 +948,7 @@ unsigned portBASE_TYPE uxSavedInterruptStatus;
        by this post). */\r
        uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();\r
        {\r
-               if( pxQueue->uxMessagesWaiting < pxQueue->uxLength )\r
+               if( ( pxQueue->uxMessagesWaiting < pxQueue->uxLength ) || ( xCopyPosition == queueOVERWRITE ) )\r
                {\r
                        traceQUEUE_SEND_FROM_ISR( pxQueue );\r
 \r
@@ -967,29 +958,53 @@ unsigned portBASE_TYPE uxSavedInterruptStatus;
                        be done when the queue is unlocked later. */\r
                        if( pxQueue->xTxLock == queueUNLOCKED )\r
                        {\r
-                               if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\r
+                               #if ( configUSE_QUEUE_SETS == 1 )\r
                                {\r
-                                       if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )\r
+                                       if( pxQueue->pxQueueSetContainer != NULL )\r
                                        {\r
-                                               /* The task waiting has a higher priority so record that a\r
-                                               context switch is required. */\r
-                                               if( pxHigherPriorityTaskWoken != NULL )\r
+                                               if( prvNotifyQueueSetContainer( pxQueue, xCopyPosition ) == pdTRUE )\r
                                                {\r
-                                                       *pxHigherPriorityTaskWoken = pdTRUE;\r
+                                                       /* The queue is a member of a queue set, and posting\r
+                                                       to the queue set caused a higher priority task to\r
+                                                       unblock.  A context switch is required. */\r
+                                                       if( pxHigherPriorityTaskWoken != NULL )\r
+                                                       {\r
+                                                               *pxHigherPriorityTaskWoken = pdTRUE;\r
+                                                       }\r
+                                               }\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\r
+                                               {\r
+                                                       if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )\r
+                                                       {\r
+                                                               /* The task waiting has a higher priority so record that a\r
+                                                               context switch is required. */\r
+                                                               if( pxHigherPriorityTaskWoken != NULL )\r
+                                                               {\r
+                                                                       *pxHigherPriorityTaskWoken = pdTRUE;\r
+                                                               }\r
+                                                       }\r
                                                }\r
                                        }\r
                                }\r
-                               else\r
+                               #else /* configUSE_QUEUE_SETS */\r
                                {\r
-                                       #if ( configUSE_QUEUE_SETS == 1 )\r
+                                       if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\r
                                        {\r
-                                               if( pxQueue->pxQueueSetContainer != NULL )\r
+                                               if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )\r
                                                {\r
-                                                       xQueueGenericSendFromISR( pxQueue->pxQueueSetContainer, &pxQueue, pxHigherPriorityTaskWoken, queueSEND_TO_BACK );\r
+                                                       /* The task waiting has a higher priority so record that a\r
+                                                       context switch is required. */\r
+                                                       if( pxHigherPriorityTaskWoken != NULL )\r
+                                                       {\r
+                                                               *pxHigherPriorityTaskWoken = pdTRUE;\r
+                                                       }\r
                                                }\r
                                        }\r
-                                       #endif /* configUSE_QUEUE_SETS */\r
                                }\r
+                               #endif /* configUSE_QUEUE_SETS */\r
                        }\r
                        else\r
                        {\r
@@ -1012,12 +1027,14 @@ unsigned portBASE_TYPE uxSavedInterruptStatus;
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-signed portBASE_TYPE xQueueGenericReceive( xQueueHandle pxQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking )\r
+signed portBASE_TYPE xQueueGenericReceive( xQueueHandle xQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking )\r
 {\r
 signed portBASE_TYPE xEntryTimeSet = pdFALSE;\r
 xTimeOutType xTimeOut;\r
 signed char *pcOriginalReadPosition;\r
+xQUEUE *pxQueue;\r
 \r
+       pxQueue = ( xQUEUE * ) xQueue;\r
        configASSERT( pxQueue );\r
        configASSERT( !( ( pvBuffer == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) );\r
 \r
@@ -1033,8 +1050,9 @@ signed char *pcOriginalReadPosition;
                        the highest priority task wanting to access the queue. */\r
                        if( pxQueue->uxMessagesWaiting > ( unsigned portBASE_TYPE ) 0 )\r
                        {\r
-                               /* Remember our read position in case we are just peeking. */\r
-                               pcOriginalReadPosition = pxQueue->pcReadFrom;\r
+                               /* Remember the read position in case the queue is only being \r
+                               peeked. */\r
+                               pcOriginalReadPosition = pxQueue->u.pcReadFrom;\r
 \r
                                prvCopyDataFromQueue( pxQueue, pvBuffer );\r
 \r
@@ -1042,7 +1060,7 @@ signed char *pcOriginalReadPosition;
                                {\r
                                        traceQUEUE_RECEIVE( pxQueue );\r
 \r
-                                       /* We are actually removing data. */\r
+                                       /* Actually removing data, not just peeking. */\r
                                        --( pxQueue->uxMessagesWaiting );\r
 \r
                                        #if ( configUSE_MUTEXES == 1 )\r
@@ -1051,7 +1069,7 @@ signed char *pcOriginalReadPosition;
                                                {\r
                                                        /* Record the information required to implement\r
                                                        priority inheritance should it become necessary. */\r
-                                                       pxQueue->pxMutexHolder = xTaskGetCurrentTaskHandle();\r
+                                                       pxQueue->pxMutexHolder = ( void * ) xTaskGetCurrentTaskHandle();\r
                                                }\r
                                        }\r
                                        #endif\r
@@ -1068,9 +1086,9 @@ signed char *pcOriginalReadPosition;
                                {\r
                                        traceQUEUE_PEEK( pxQueue );\r
 \r
-                                       /* The data is not being removed, so reset the read     \r
+                                       /* The data is not being removed, so reset the read\r
                                        pointer. */\r
-                                       pxQueue->pcReadFrom = pcOriginalReadPosition;\r
+                                       pxQueue->u.pcReadFrom = pcOriginalReadPosition;\r
 \r
                                        /* The data is being left in the queue, so see if there are\r
                                        any other tasks waiting for the data. */\r
@@ -1084,17 +1102,6 @@ signed char *pcOriginalReadPosition;
                                                        portYIELD_WITHIN_API();\r
                                                }\r
                                        }\r
-                                       else\r
-                                       {\r
-                                               #if ( configUSE_QUEUE_SETS == 1 )\r
-                                               {\r
-                                                       if( pxQueue->pxQueueSetContainer != NULL )\r
-                                                       {\r
-                                                               xQueueGenericSend( pxQueue->pxQueueSetContainer, &pxQueue, 0, queueSEND_TO_BACK );\r
-                                                       }\r
-                                               }\r
-                                               #endif /* configUSE_QUEUE_SETS */\r
-                                       }\r
                                }\r
 \r
                                taskEXIT_CRITICAL();\r
@@ -1172,17 +1179,19 @@ signed char *pcOriginalReadPosition;
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle pxQueue, void * const pvBuffer, signed portBASE_TYPE *pxHigherPriorityTaskWoken )\r
+signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle xQueue, void * const pvBuffer, signed portBASE_TYPE *pxHigherPriorityTaskWoken )\r
 {\r
 signed portBASE_TYPE xReturn;\r
 unsigned portBASE_TYPE uxSavedInterruptStatus;\r
+xQUEUE *pxQueue;\r
 \r
+       pxQueue = ( xQUEUE * ) xQueue;\r
        configASSERT( pxQueue );\r
        configASSERT( !( ( pvBuffer == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) );\r
 \r
        uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();\r
        {\r
-               /* We cannot block from an ISR, so check there is data available. */\r
+               /* Cannot block in an ISR, so check there is data available. */\r
                if( pxQueue->uxMessagesWaiting > ( unsigned portBASE_TYPE ) 0 )\r
                {\r
                        traceQUEUE_RECEIVE_FROM_ISR( pxQueue );\r
@@ -1190,9 +1199,10 @@ unsigned portBASE_TYPE uxSavedInterruptStatus;
                        prvCopyDataFromQueue( pxQueue, pvBuffer );\r
                        --( pxQueue->uxMessagesWaiting );\r
 \r
-                       /* If the queue is locked we will not modify the event list.  Instead\r
-                       we update the lock count so the task that unlocks the queue will know\r
-                       that an ISR has removed data while the queue was locked. */\r
+                       /* If the queue is locked the event list will not be modified.  \r
+                       Instead update the lock count so the task that unlocks the queue \r
+                       will know that an ISR has removed data while the queue was \r
+                       locked. */\r
                        if( pxQueue->xRxLock == queueUNLOCKED )\r
                        {\r
                                if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )\r
@@ -1229,38 +1239,83 @@ unsigned portBASE_TYPE uxSavedInterruptStatus;
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle pxQueue )\r
+signed portBASE_TYPE xQueuePeekFromISR( xQueueHandle xQueue, void * const pvBuffer )\r
 {\r
-unsigned portBASE_TYPE uxReturn;\r
+signed portBASE_TYPE xReturn;\r
+unsigned portBASE_TYPE uxSavedInterruptStatus;\r
+signed char *pcOriginalReadPosition;\r
+xQUEUE *pxQueue;\r
 \r
+       pxQueue = ( xQUEUE * ) xQueue;\r
        configASSERT( pxQueue );\r
+       configASSERT( !( ( pvBuffer == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) );\r
+\r
+       uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();\r
+       {\r
+               /* Cannot block in an ISR, so check there is data available. */\r
+               if( pxQueue->uxMessagesWaiting > ( unsigned portBASE_TYPE ) 0 )\r
+               {\r
+                       traceQUEUE_PEEK_FROM_ISR( pxQueue );\r
+\r
+                       /* Remember the read position so it can be reset as nothing is\r
+                       actually being removed from the queue. */\r
+                       pcOriginalReadPosition = pxQueue->u.pcReadFrom;\r
+                       prvCopyDataFromQueue( pxQueue, pvBuffer );\r
+                       pxQueue->u.pcReadFrom = pcOriginalReadPosition;\r
+\r
+                       xReturn = pdPASS;\r
+               }\r
+               else\r
+               {\r
+                       xReturn = pdFAIL;\r
+                       traceQUEUE_PEEK_FROM_ISR_FAILED( pxQueue );\r
+               }\r
+       }\r
+       portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );\r
+\r
+       return xReturn;\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle xQueue )\r
+{\r
+unsigned portBASE_TYPE uxReturn;\r
+\r
+       configASSERT( xQueue );\r
 \r
        taskENTER_CRITICAL();\r
-               uxReturn = pxQueue->uxMessagesWaiting;\r
+               uxReturn = ( ( xQUEUE * ) xQueue )->uxMessagesWaiting;\r
        taskEXIT_CRITICAL();\r
 \r
        return uxReturn;\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-unsigned portBASE_TYPE uxQueueMessagesWaitingFromISR( const xQueueHandle pxQueue )\r
+unsigned portBASE_TYPE uxQueueMessagesWaitingFromISR( const xQueueHandle xQueue )\r
 {\r
 unsigned portBASE_TYPE uxReturn;\r
 \r
-       configASSERT( pxQueue );\r
+       configASSERT( xQueue );\r
 \r
-       uxReturn = pxQueue->uxMessagesWaiting;\r
+       uxReturn = ( ( xQUEUE * ) xQueue )->uxMessagesWaiting;\r
 \r
        return uxReturn;\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-void vQueueDelete( xQueueHandle pxQueue )\r
+void vQueueDelete( xQueueHandle xQueue )\r
 {\r
+xQUEUE *pxQueue;\r
+\r
+       pxQueue = ( xQUEUE * ) xQueue;\r
        configASSERT( pxQueue );\r
 \r
        traceQUEUE_DELETE( pxQueue );\r
-       vQueueUnregisterQueue( pxQueue );\r
+       #if ( configQUEUE_REGISTRY_SIZE > 0 )\r
+       {\r
+               vQueueUnregisterQueue( pxQueue );\r
+       }\r
+       #endif\r
        vPortFree( pxQueue->pcHead );\r
        vPortFree( pxQueue );\r
 }\r
@@ -1268,9 +1323,9 @@ void vQueueDelete( xQueueHandle pxQueue )
 \r
 #if ( configUSE_TRACE_FACILITY == 1 )\r
 \r
-       unsigned char ucQueueGetQueueNumber( xQueueHandle pxQueue )\r
+       unsigned char ucQueueGetQueueNumber( xQueueHandle xQueue )\r
        {\r
-               return pxQueue->ucQueueNumber;\r
+               return ( ( xQUEUE * ) xQueue )->ucQueueNumber;\r
        }\r
 \r
 #endif /* configUSE_TRACE_FACILITY */\r
@@ -1278,9 +1333,9 @@ void vQueueDelete( xQueueHandle pxQueue )
 \r
 #if ( configUSE_TRACE_FACILITY == 1 )\r
 \r
-       void vQueueSetQueueNumber( xQueueHandle pxQueue, unsigned char ucQueueNumber )\r
+       void vQueueSetQueueNumber( xQueueHandle xQueue, unsigned char ucQueueNumber )\r
        {\r
-               pxQueue->ucQueueNumber = ucQueueNumber;\r
+               ( ( xQUEUE * ) xQueue )->ucQueueNumber = ucQueueNumber;\r
        }\r
 \r
 #endif /* configUSE_TRACE_FACILITY */\r
@@ -1288,9 +1343,9 @@ void vQueueDelete( xQueueHandle pxQueue )
 \r
 #if ( configUSE_TRACE_FACILITY == 1 )\r
 \r
-       unsigned char ucQueueGetQueueType( xQueueHandle pxQueue )\r
+       unsigned char ucQueueGetQueueType( xQueueHandle xQueue )\r
        {\r
-               return pxQueue->ucQueueType;\r
+               return ( ( xQUEUE * ) xQueue )->ucQueueType;\r
        }\r
 \r
 #endif /* configUSE_TRACE_FACILITY */\r
@@ -1309,11 +1364,11 @@ static void prvCopyDataToQueue( xQUEUE *pxQueue, const void *pvItemToQueue, port
                                pxQueue->pxMutexHolder = NULL;\r
                        }\r
                }\r
-               #endif\r
+               #endif /* configUSE_MUTEXES */\r
        }\r
        else if( xPosition == queueSEND_TO_BACK )\r
        {\r
-               memcpy( ( void * ) pxQueue->pcWriteTo, pvItemToQueue, ( unsigned ) pxQueue->uxItemSize );\r
+               memcpy( ( void * ) pxQueue->pcWriteTo, pvItemToQueue, ( size_t ) pxQueue->uxItemSize );\r
                pxQueue->pcWriteTo += pxQueue->uxItemSize;\r
                if( pxQueue->pcWriteTo >= pxQueue->pcTail )\r
                {\r
@@ -1322,11 +1377,23 @@ static void prvCopyDataToQueue( xQUEUE *pxQueue, const void *pvItemToQueue, port
        }\r
        else\r
        {\r
-               memcpy( ( void * ) pxQueue->pcReadFrom, pvItemToQueue, ( unsigned ) pxQueue->uxItemSize );\r
-               pxQueue->pcReadFrom -= pxQueue->uxItemSize;\r
-               if( pxQueue->pcReadFrom < pxQueue->pcHead )\r
+               memcpy( ( void * ) pxQueue->u.pcReadFrom, pvItemToQueue, ( size_t ) pxQueue->uxItemSize );\r
+               pxQueue->u.pcReadFrom -= pxQueue->uxItemSize;\r
+               if( pxQueue->u.pcReadFrom < pxQueue->pcHead )\r
                {\r
-                       pxQueue->pcReadFrom = ( pxQueue->pcTail - pxQueue->uxItemSize );\r
+                       pxQueue->u.pcReadFrom = ( pxQueue->pcTail - pxQueue->uxItemSize );\r
+               }\r
+\r
+               if( xPosition == queueOVERWRITE )\r
+               {\r
+                       if( pxQueue->uxMessagesWaiting > 0 )\r
+                       {\r
+                               /* An item is not being added but overwritten, so subtract \r
+                               one from the recorded number of items in the queue so when \r
+                               one is added again below the number of recorded items remains \r
+                               correct. */\r
+                               --( pxQueue->uxMessagesWaiting );\r
+                       }\r
                }\r
        }\r
 \r
@@ -1338,17 +1405,17 @@ static void prvCopyDataFromQueue( xQUEUE * const pxQueue, const void *pvBuffer )
 {\r
        if( pxQueue->uxQueueType != queueQUEUE_IS_MUTEX )\r
        {\r
-               pxQueue->pcReadFrom += pxQueue->uxItemSize;\r
-               if( pxQueue->pcReadFrom >= pxQueue->pcTail )\r
+               pxQueue->u.pcReadFrom += pxQueue->uxItemSize;\r
+               if( pxQueue->u.pcReadFrom >= pxQueue->pcTail )\r
                {\r
-                       pxQueue->pcReadFrom = pxQueue->pcHead;\r
+                       pxQueue->u.pcReadFrom = pxQueue->pcHead;\r
                }\r
-               memcpy( ( void * ) pvBuffer, ( void * ) pxQueue->pcReadFrom, ( unsigned ) pxQueue->uxItemSize );\r
+               memcpy( ( void * ) pvBuffer, ( void * ) pxQueue->u.pcReadFrom, ( size_t ) pxQueue->uxItemSize );\r
        }\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-static void prvUnlockQueue( xQueueHandle pxQueue )\r
+static void prvUnlockQueue( xQUEUE *pxQueue )\r
 {\r
        /* THIS FUNCTION MUST BE CALLED WITH THE SCHEDULER SUSPENDED. */\r
 \r
@@ -1363,39 +1430,58 @@ static void prvUnlockQueue( xQueueHandle pxQueue )
                {\r
                        /* Data was posted while the queue was locked.  Are any tasks\r
                        blocked waiting for data to become available? */\r
-                       if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\r
+                       #if ( configUSE_QUEUE_SETS == 1 )\r
                        {\r
-                               /* Tasks that are removed from the event list will get added to\r
-                               the pending ready list as the scheduler is still suspended. */\r
-                               if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )\r
+                               if( pxQueue->pxQueueSetContainer != NULL )\r
                                {\r
-                                       /* The task waiting has a higher priority so record that a\r
-                                       context switch is required. */\r
-                                       vTaskMissedYield();\r
+                                       if( prvNotifyQueueSetContainer( pxQueue, queueSEND_TO_BACK ) == pdTRUE )\r
+                                       {\r
+                                               /* The queue is a member of a queue set, and posting to\r
+                                               the queue set caused a higher priority task to unblock.\r
+                                               A context switch is required. */\r
+                                               vTaskMissedYield();\r
+                                       }\r
                                }\r
                                else\r
                                {\r
-                                       #if ( configUSE_QUEUE_SETS == 1 )\r
+                                       /* Tasks that are removed from the event list will get added to\r
+                                       the pending ready list as the scheduler is still suspended. */\r
+                                       if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\r
                                        {\r
-                                               if( pxQueue->pxQueueSetContainer != NULL )\r
+                                               if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )\r
                                                {\r
-                                                       portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;\r
-                                                       xQueueGenericSendFromISR( pxQueue->pxQueueSetContainer, &pxQueue, &xHigherPriorityTaskWoken, queueSEND_TO_BACK );\r
-                                                       if( xHigherPriorityTaskWoken != pdFALSE )\r
-                                                       {\r
-                                                               vTaskMissedYield();\r
-                                                       }\r
+                                                       /* The task waiting has a higher priority so record that a\r
+                                                       context switch is required. */\r
+                                                       vTaskMissedYield();\r
                                                }\r
                                        }\r
-                                       #endif /* configUSE_QUEUE_SETS */\r
+                                       else\r
+                                       {\r
+                                               break;\r
+                                       }\r
                                }\r
-\r
-                               --( pxQueue->xTxLock );\r
                        }\r
-                       else\r
+                       #else /* configUSE_QUEUE_SETS */\r
                        {\r
-                               break;\r
+                               /* Tasks that are removed from the event list will get added to\r
+                               the pending ready list as the scheduler is still suspended. */\r
+                               if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\r
+                               {\r
+                                       if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )\r
+                                       {\r
+                                               /* The task waiting has a higher priority so record that a\r
+                                               context switch is required. */\r
+                                               vTaskMissedYield();\r
+                                       }\r
+                               }\r
+                               else\r
+                               {\r
+                                       break;\r
+                               }\r
                        }\r
+                       #endif /* configUSE_QUEUE_SETS */\r
+\r
+                       --( pxQueue->xTxLock );\r
                }\r
 \r
                pxQueue->xTxLock = queueUNLOCKED;\r
@@ -1428,47 +1514,79 @@ static void prvUnlockQueue( xQueueHandle pxQueue )
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-static signed portBASE_TYPE prvIsQueueEmpty( const xQueueHandle pxQueue )\r
+static signed portBASE_TYPE prvIsQueueEmpty( const xQUEUE *pxQueue )\r
 {\r
 signed portBASE_TYPE xReturn;\r
 \r
        taskENTER_CRITICAL();\r
-               xReturn = ( pxQueue->uxMessagesWaiting == ( unsigned portBASE_TYPE ) 0 );\r
+       {\r
+               if( pxQueue->uxMessagesWaiting == 0 )\r
+               {\r
+                       xReturn = pdTRUE;\r
+               }\r
+               else\r
+               {\r
+                       xReturn = pdFALSE;\r
+               }\r
+       }\r
        taskEXIT_CRITICAL();\r
 \r
        return xReturn;\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-signed portBASE_TYPE xQueueIsQueueEmptyFromISR( const xQueueHandle pxQueue )\r
+signed portBASE_TYPE xQueueIsQueueEmptyFromISR( const xQueueHandle xQueue )\r
 {\r
 signed portBASE_TYPE xReturn;\r
 \r
-       configASSERT( pxQueue );\r
-       xReturn = ( pxQueue->uxMessagesWaiting == ( unsigned portBASE_TYPE ) 0 );\r
+       configASSERT( xQueue );\r
+       if( ( ( xQUEUE * ) xQueue )->uxMessagesWaiting == 0 )\r
+       {\r
+               xReturn = pdTRUE;\r
+       }\r
+       else\r
+       {\r
+               xReturn = pdFALSE;\r
+       }\r
 \r
        return xReturn;\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-static signed portBASE_TYPE prvIsQueueFull( const xQueueHandle pxQueue )\r
+static signed portBASE_TYPE prvIsQueueFull( const xQUEUE *pxQueue )\r
 {\r
 signed portBASE_TYPE xReturn;\r
 \r
        taskENTER_CRITICAL();\r
-               xReturn = ( pxQueue->uxMessagesWaiting == pxQueue->uxLength );\r
+       {\r
+               if( pxQueue->uxMessagesWaiting == pxQueue->uxLength )\r
+               {\r
+                       xReturn = pdTRUE;\r
+               }\r
+               else\r
+               {\r
+                       xReturn = pdFALSE;\r
+               }\r
+       }\r
        taskEXIT_CRITICAL();\r
 \r
        return xReturn;\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-signed portBASE_TYPE xQueueIsQueueFullFromISR( const xQueueHandle pxQueue )\r
+signed portBASE_TYPE xQueueIsQueueFullFromISR( const xQueueHandle xQueue )\r
 {\r
 signed portBASE_TYPE xReturn;\r
 \r
-       configASSERT( pxQueue );\r
-       xReturn = ( pxQueue->uxMessagesWaiting == pxQueue->uxLength );\r
+       configASSERT( xQueue );\r
+       if( ( ( xQUEUE * ) xQueue )->uxMessagesWaiting == ( ( xQUEUE * ) xQueue )->uxLength )\r
+       {\r
+               xReturn = pdTRUE;\r
+       }\r
+       else\r
+       {\r
+               xReturn = pdFALSE;\r
+       }\r
 \r
        return xReturn;\r
 }\r
@@ -1476,9 +1594,12 @@ signed portBASE_TYPE xReturn;
 \r
 #if ( configUSE_CO_ROUTINES == 1 )\r
 \r
-       signed portBASE_TYPE xQueueCRSend( xQueueHandle pxQueue, const void *pvItemToQueue, portTickType xTicksToWait )\r
+       signed portBASE_TYPE xQueueCRSend( xQueueHandle xQueue, const void *pvItemToQueue, portTickType xTicksToWait )\r
        {\r
        signed portBASE_TYPE xReturn;\r
+       xQUEUE *pxQueue;\r
+\r
+               pxQueue = ( xQUEUE * ) xQueue;\r
 \r
                /* If the queue is already full we may have to block.  A critical section\r
                is required to prevent an interrupt removing something from the queue\r
@@ -1506,8 +1627,6 @@ signed portBASE_TYPE xReturn;
                }\r
                portENABLE_INTERRUPTS();\r
 \r
-               portNOP();\r
-\r
                portDISABLE_INTERRUPTS();\r
                {\r
                        if( pxQueue->uxMessagesWaiting < pxQueue->uxLength )\r
@@ -1546,9 +1665,12 @@ signed portBASE_TYPE xReturn;
 \r
 #if ( configUSE_CO_ROUTINES == 1 )\r
 \r
-       signed portBASE_TYPE xQueueCRReceive( xQueueHandle pxQueue, void *pvBuffer, portTickType xTicksToWait )\r
+       signed portBASE_TYPE xQueueCRReceive( xQueueHandle xQueue, void *pvBuffer, portTickType xTicksToWait )\r
        {\r
        signed portBASE_TYPE xReturn;\r
+       xQUEUE *pxQueue;\r
+\r
+               pxQueue = ( xQUEUE * ) xQueue;\r
 \r
                /* If the queue is already empty we may have to block.  A critical section\r
                is required to prevent an interrupt adding something to the queue\r
@@ -1576,20 +1698,18 @@ signed portBASE_TYPE xReturn;
                }\r
                portENABLE_INTERRUPTS();\r
 \r
-               portNOP();\r
-\r
                portDISABLE_INTERRUPTS();\r
                {\r
                        if( pxQueue->uxMessagesWaiting > ( unsigned portBASE_TYPE ) 0 )\r
                        {\r
                                /* Data is available from the queue. */\r
-                               pxQueue->pcReadFrom += pxQueue->uxItemSize;\r
-                               if( pxQueue->pcReadFrom >= pxQueue->pcTail )\r
+                               pxQueue->u.pcReadFrom += pxQueue->uxItemSize;\r
+                               if( pxQueue->u.pcReadFrom >= pxQueue->pcTail )\r
                                {\r
-                                       pxQueue->pcReadFrom = pxQueue->pcHead;\r
+                                       pxQueue->u.pcReadFrom = pxQueue->pcHead;\r
                                }\r
                                --( pxQueue->uxMessagesWaiting );\r
-                               memcpy( ( void * ) pvBuffer, ( void * ) pxQueue->pcReadFrom, ( unsigned ) pxQueue->uxItemSize );\r
+                               memcpy( ( void * ) pvBuffer, ( void * ) pxQueue->u.pcReadFrom, ( unsigned ) pxQueue->uxItemSize );\r
 \r
                                xReturn = pdPASS;\r
 \r
@@ -1621,8 +1741,12 @@ signed portBASE_TYPE xReturn;
 \r
 #if ( configUSE_CO_ROUTINES == 1 )\r
 \r
-       signed portBASE_TYPE xQueueCRSendFromISR( xQueueHandle pxQueue, const void *pvItemToQueue, signed portBASE_TYPE xCoRoutinePreviouslyWoken )\r
+       signed portBASE_TYPE xQueueCRSendFromISR( xQueueHandle xQueue, const void *pvItemToQueue, signed portBASE_TYPE xCoRoutinePreviouslyWoken )\r
        {\r
+       xQUEUE *pxQueue;\r
+\r
+               pxQueue = ( xQUEUE * ) xQueue;\r
+\r
                /* Cannot block within an ISR so if there is no space on the queue then\r
                exit without doing anything. */\r
                if( pxQueue->uxMessagesWaiting < pxQueue->uxLength )\r
@@ -1651,22 +1775,25 @@ signed portBASE_TYPE xReturn;
 \r
 #if ( configUSE_CO_ROUTINES == 1 )\r
 \r
-       signed portBASE_TYPE xQueueCRReceiveFromISR( xQueueHandle pxQueue, void *pvBuffer, signed portBASE_TYPE *pxCoRoutineWoken )\r
+       signed portBASE_TYPE xQueueCRReceiveFromISR( xQueueHandle xQueue, void *pvBuffer, signed portBASE_TYPE *pxCoRoutineWoken )\r
        {\r
        signed portBASE_TYPE xReturn;\r
+       xQUEUE * pxQueue;\r
+\r
+               pxQueue = ( xQUEUE * ) xQueue;\r
 \r
                /* We cannot block from an ISR, so check there is data available. If\r
                not then just leave without doing anything. */\r
                if( pxQueue->uxMessagesWaiting > ( unsigned portBASE_TYPE ) 0 )\r
                {\r
                        /* Copy the data from the queue. */\r
-                       pxQueue->pcReadFrom += pxQueue->uxItemSize;\r
-                       if( pxQueue->pcReadFrom >= pxQueue->pcTail )\r
+                       pxQueue->u.pcReadFrom += pxQueue->uxItemSize;\r
+                       if( pxQueue->u.pcReadFrom >= pxQueue->pcTail )\r
                        {\r
-                               pxQueue->pcReadFrom = pxQueue->pcHead;\r
+                               pxQueue->u.pcReadFrom = pxQueue->pcHead;\r
                        }\r
                        --( pxQueue->uxMessagesWaiting );\r
-                       memcpy( ( void * ) pvBuffer, ( void * ) pxQueue->pcReadFrom, ( unsigned ) pxQueue->uxItemSize );\r
+                       memcpy( ( void * ) pvBuffer, ( void * ) pxQueue->u.pcReadFrom, ( unsigned ) pxQueue->uxItemSize );\r
 \r
                        if( ( *pxCoRoutineWoken ) == pdFALSE )\r
                        {\r
@@ -1717,7 +1844,7 @@ signed portBASE_TYPE xReturn;
 \r
 #if ( configQUEUE_REGISTRY_SIZE > 0 )\r
 \r
-       static void vQueueUnregisterQueue( xQueueHandle xQueue )\r
+       void vQueueUnregisterQueue( xQueueHandle xQueue )\r
        {\r
        unsigned portBASE_TYPE ux;\r
 \r
@@ -1740,8 +1867,12 @@ signed portBASE_TYPE xReturn;
 \r
 #if ( configUSE_TIMERS == 1 )\r
 \r
-       void vQueueWaitForMessageRestricted( xQueueHandle pxQueue, portTickType xTicksToWait )\r
+       void vQueueWaitForMessageRestricted( xQueueHandle xQueue, portTickType xTicksToWait )\r
        {\r
+       xQUEUE *pxQueue;\r
+\r
+               pxQueue = ( xQUEUE * ) xQueue;\r
+\r
                /* This function should not be called by application code hence the\r
                'Restricted' in its name.  It is not part of the public API.  It is\r
                designed for use by kernel code, and has special calling requirements.\r
@@ -1770,13 +1901,13 @@ signed portBASE_TYPE xReturn;
 \r
 #if ( configUSE_QUEUE_SETS == 1 )\r
 \r
-       xQueueSetHandle xQueueSetCreate( unsigned portBASE_TYPE uxEventQueueLength )\r
+       xQueueSetHandle xQueueCreateSet( unsigned portBASE_TYPE uxEventQueueLength )\r
        {\r
-       xQUEUE *pxQueue;\r
+       xQueueSetHandle pxQueue;\r
 \r
                pxQueue = xQueueGenericCreate( uxEventQueueLength, sizeof( xQUEUE * ), queueQUEUE_TYPE_SET );\r
 \r
-               return ( xQueueSetHandle ) pxQueue;\r
+               return pxQueue;\r
        }\r
 \r
 #endif /* configUSE_QUEUE_SETS */\r
@@ -1784,19 +1915,26 @@ signed portBASE_TYPE xReturn;
 \r
 #if ( configUSE_QUEUE_SETS == 1 )\r
 \r
-       portBASE_TYPE xQueueAddToQueueSet( xQueueHandle xQueue, xQueueSetHandle xQueueSet )\r
+       portBASE_TYPE xQueueAddToSet( xQueueSetMemberHandle xQueueOrSemaphore, xQueueSetHandle xQueueSet )\r
        {\r
        portBASE_TYPE xReturn;\r
 \r
-               if( xQueue->pxQueueSetContainer != NULL )\r
+               if( ( ( xQUEUE * ) xQueueOrSemaphore )->pxQueueSetContainer != NULL )\r
                {\r
+                       /* Cannot add a queue/semaphore to more than one queue set. */\r
+                       xReturn = pdFAIL;\r
+               }\r
+               else if( ( ( xQUEUE * ) xQueueOrSemaphore )->uxMessagesWaiting != 0 )\r
+               {\r
+                       /* Cannot add a queue/semaphore to a queue set if there are already\r
+                       items in the queue/semaphore. */\r
                        xReturn = pdFAIL;\r
                }\r
                else\r
                {\r
                        taskENTER_CRITICAL();\r
                        {\r
-                               xQueue->pxQueueSetContainer = xQueueSet;\r
+                               ( ( xQUEUE * ) xQueueOrSemaphore )->pxQueueSetContainer = xQueueSet;\r
                        }\r
                        taskEXIT_CRITICAL();\r
                        xReturn = pdPASS;\r
@@ -1810,19 +1948,31 @@ signed portBASE_TYPE xReturn;
 \r
 #if ( configUSE_QUEUE_SETS == 1 )\r
 \r
-       portBASE_TYPE xQueueRemoveFromQueueSet( xQueueSetHandle xQueueSet, xQueueHandle xQueue )\r
+       portBASE_TYPE xQueueRemoveFromSet( xQueueSetMemberHandle xQueueOrSemaphore, xQueueSetHandle xQueueSet )\r
        {\r
        portBASE_TYPE xReturn;\r
+       xQUEUE *pxQueueOrSemaphore;\r
+\r
+               pxQueueOrSemaphore = ( xQUEUE * ) xQueueOrSemaphore;\r
 \r
-               if( xQueue->pxQueueSetContainer != xQueueSet )\r
+               if( pxQueueOrSemaphore->pxQueueSetContainer != xQueueSet )\r
+               {\r
+                       /* The queue was not a member of the set. */\r
+                       xReturn = pdFAIL;\r
+               }\r
+               else if( pxQueueOrSemaphore->uxMessagesWaiting != 0 )\r
                {\r
+                       /* It is dangerous to remove a queue from a set when the queue is\r
+                       not empty because the queue set will still hold pending events for\r
+                       the queue. */\r
                        xReturn = pdFAIL;\r
                }\r
                else\r
                {\r
                        taskENTER_CRITICAL();\r
                        {\r
-                               xQueue->pxQueueSetContainer = NULL;\r
+                               /* The queue is no longer contained in the set. */\r
+                               pxQueueOrSemaphore->pxQueueSetContainer = NULL;\r
                        }\r
                        taskEXIT_CRITICAL();\r
                        xReturn = pdPASS;\r
@@ -1836,10 +1986,10 @@ signed portBASE_TYPE xReturn;
 \r
 #if ( configUSE_QUEUE_SETS == 1 )\r
 \r
-       xQueueHandle xQueueReadMultiple( xQueueSetHandle xQueueSet, portTickType xBlockTimeTicks )\r
+       xQueueSetMemberHandle xQueueSelectFromSet( xQueueSetHandle xQueueSet, portTickType xBlockTimeTicks )\r
        {\r
-       xQueueHandle xReturn = NULL;\r
-       \r
+       xQueueSetMemberHandle xReturn = NULL;\r
+\r
                xQueueGenericReceive( ( xQueueHandle ) xQueueSet, &xReturn, xBlockTimeTicks, pdFALSE );\r
                return xReturn;\r
        }\r
@@ -1849,23 +1999,38 @@ signed portBASE_TYPE xReturn;
 \r
 #if ( configUSE_QUEUE_SETS == 1 )\r
 \r
-       static portBASE_TYPE prvCheckForMembershipOfQueueSet( xQUEUE *pxQueue, portBASE_TYPE xCopyPosition )\r
+       xQueueSetMemberHandle xQueueSelectFromSetFromISR( xQueueSetHandle xQueueSet )\r
+       {\r
+       xQueueSetMemberHandle xReturn = NULL;\r
+\r
+               xQueueReceiveFromISR( ( xQueueHandle ) xQueueSet, &xReturn, NULL );\r
+               return xReturn;\r
+       }\r
+\r
+#endif /* configUSE_QUEUE_SETS */\r
+/*-----------------------------------------------------------*/\r
+\r
+#if ( configUSE_QUEUE_SETS == 1 )\r
+\r
+       static portBASE_TYPE prvNotifyQueueSetContainer( xQUEUE *pxQueue, portBASE_TYPE xCopyPosition )\r
        {\r
        xQUEUE *pxQueueSetContainer = pxQueue->pxQueueSetContainer;\r
        portBASE_TYPE xReturn = pdFALSE;\r
 \r
-               if( pxQueueSetContainer != NULL )\r
+               configASSERT( pxQueueSetContainer );\r
+               configASSERT( pxQueueSetContainer->uxMessagesWaiting < pxQueueSetContainer->uxLength );\r
+\r
+               if( pxQueueSetContainer->uxMessagesWaiting < pxQueueSetContainer->uxLength )\r
                {\r
-                       if( pxQueueSetContainer->uxMessagesWaiting < pxQueueSetContainer->uxLength )\r
+                       traceQUEUE_SEND( pxQueueSetContainer );\r
+                       /* The data copies is the handle of the queue that contains data. */\r
+                       prvCopyDataToQueue( pxQueueSetContainer, &pxQueue, xCopyPosition );\r
+                       if( listLIST_IS_EMPTY( &( pxQueueSetContainer->xTasksWaitingToReceive ) ) == pdFALSE )\r
                        {\r
-                               prvCopyDataToQueue( pxQueueSetContainer, &pxQueue, xCopyPosition );\r
-                               if( listLIST_IS_EMPTY( &( pxQueueSetContainer->xTasksWaitingToReceive ) ) == pdFALSE )\r
+                               if( xTaskRemoveFromEventList( &( pxQueueSetContainer->xTasksWaitingToReceive ) ) != pdFALSE )\r
                                {\r
-                                       if( xTaskRemoveFromEventList( &( pxQueue->pxQueueSetContainer->xTasksWaitingToReceive ) ) != pdFALSE )\r
-                                       {\r
-                                               /* The task waiting has a higher priority */\r
-                                               xReturn = pdTRUE;\r
-                                       }\r
+                                       /* The task waiting has a higher priority */\r
+                                       xReturn = pdTRUE;\r
                                }\r
                        }\r
                }\r