]> 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 a97f868c1ae31eef94f4d0aa585a451daa336122..b9024d5354da203f0b1c4920fc1e882846f9f82f 100644 (file)
@@ -1,5 +1,5 @@
 /*\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
     http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\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
-    http://www.FreeRTOS.org - Documentation, training, latest versions, license\r
-    and contact details.\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
-    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.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
+    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
@@ -90,13 +96,22 @@ task.h is included from an application file. */
 \r
 #define queueERRONEOUS_UNBLOCK                 ( -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
@@ -113,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
@@ -157,10 +177,6 @@ typedef struct QueueDefinition
        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 prvQueueUnregisterQueue( xQueueHandle xQueue ) PRIVILEGED_FUNCTION;\r
-\r
 #endif /* configQUEUE_REGISTRY_SIZE */\r
 \r
 /*\r
@@ -203,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 prvNotifyQueueSetContainer( xQUEUE *pxQueue, portBASE_TYPE xCopyPosition );\r
+       static portBASE_TYPE prvNotifyQueueSetContainer( xQUEUE *pxQueue, portBASE_TYPE xCopyPosition ) PRIVILEGED_FUNCTION;\r
 #endif\r
 \r
 /*-----------------------------------------------------------*/\r
@@ -239,7 +255,7 @@ xQUEUE *pxQueue;
                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
@@ -352,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
@@ -442,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
@@ -451,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
@@ -492,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
@@ -505,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
@@ -554,6 +570,7 @@ xQUEUE *pxQueue;
        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
@@ -562,9 +579,11 @@ xQUEUE *pxQueue;
        {\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
@@ -798,7 +817,7 @@ xQUEUE *pxQueue;
                                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
@@ -815,7 +834,7 @@ xQUEUE *pxQueue;
                                                        {\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
@@ -834,7 +853,7 @@ xQUEUE *pxQueue;
 \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
@@ -920,6 +939,7 @@ xQUEUE *pxQueue;
        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
@@ -928,7 +948,7 @@ xQUEUE *pxQueue;
        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
@@ -1030,8 +1050,9 @@ xQUEUE *pxQueue;
                        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
@@ -1039,7 +1060,7 @@ xQUEUE *pxQueue;
                                {\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
@@ -1048,7 +1069,7 @@ xQUEUE *pxQueue;
                                                {\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
@@ -1067,7 +1088,7 @@ xQUEUE *pxQueue;
 \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
@@ -1170,7 +1191,7 @@ xQUEUE *pxQueue;
 \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
@@ -1178,9 +1199,10 @@ xQUEUE *pxQueue;
                        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
@@ -1217,6 +1239,44 @@ xQUEUE *pxQueue;
 }\r
 /*-----------------------------------------------------------*/\r
 \r
+signed portBASE_TYPE xQueuePeekFromISR( xQueueHandle xQueue, void * const pvBuffer )\r
+{\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
@@ -1251,7 +1311,11 @@ xQUEUE *pxQueue;
        configASSERT( pxQueue );\r
 \r
        traceQUEUE_DELETE( pxQueue );\r
-       prvQueueUnregisterQueue( pxQueue );\r
+       #if ( configQUEUE_REGISTRY_SIZE > 0 )\r
+       {\r
+               vQueueUnregisterQueue( pxQueue );\r
+       }\r
+       #endif\r
        vPortFree( pxQueue->pcHead );\r
        vPortFree( pxQueue );\r
 }\r
@@ -1300,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
@@ -1313,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->u.pcReadFrom = ( pxQueue->pcTail - pxQueue->uxItemSize );\r
+               }\r
+\r
+               if( xPosition == queueOVERWRITE )\r
                {\r
-                       pxQueue->pcReadFrom = ( pxQueue->pcTail - pxQueue->uxItemSize );\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
@@ -1329,12 +1405,12 @@ 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
@@ -1627,13 +1703,13 @@ signed portBASE_TYPE xReturn;
                        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
@@ -1711,13 +1787,13 @@ signed portBASE_TYPE xReturn;
                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
@@ -1768,7 +1844,7 @@ signed portBASE_TYPE xReturn;
 \r
 #if ( configQUEUE_REGISTRY_SIZE > 0 )\r
 \r
-       static void prvQueueUnregisterQueue( xQueueHandle xQueue )\r
+       void vQueueUnregisterQueue( xQueueHandle xQueue )\r
        {\r
        unsigned portBASE_TYPE ux;\r
 \r
@@ -1845,6 +1921,13 @@ signed portBASE_TYPE xReturn;
 \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