]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Source/queue.c
Kernel changes to improve power saving:
[freertos] / FreeRTOS / Source / queue.c
index 12a79f93cedff2defc56bf1af269151015c564db..931116fb8bed810f488b9f865854ccaf1a5084f2 100644 (file)
@@ -1,60 +1,64 @@
 /*\r
-    FreeRTOS V8.1.2 - Copyright (C) 2014 Real Time Engineers Ltd.\r
+    FreeRTOS V8.2.1 - Copyright (C) 2015 Real Time Engineers Ltd.\r
     All rights reserved\r
 \r
     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
 \r
-    ***************************************************************************\r
-     *                                                                       *\r
-     *    FreeRTOS provides completely free yet professionally developed,    *\r
-     *    robust, strictly quality controlled, supported, and cross          *\r
-     *    platform software that has become a de facto standard.             *\r
-     *                                                                       *\r
-     *    Help yourself get started quickly and support the FreeRTOS         *\r
-     *    project by purchasing a FreeRTOS tutorial book, reference          *\r
-     *    manual, or both from: http://www.FreeRTOS.org/Documentation        *\r
-     *                                                                       *\r
-     *    Thank you!                                                         *\r
-     *                                                                       *\r
-    ***************************************************************************\r
-\r
     This file is part of the FreeRTOS distribution.\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
 \r
+    ***************************************************************************\r
     >>!   NOTE: The modification to the GPL is included to allow you to     !<<\r
     >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
     >>!   obliged to provide the source code for proprietary components     !<<\r
     >>!   outside of the FreeRTOS kernel.                                   !<<\r
+    ***************************************************************************\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.  Full license text is available from the following\r
+    FOR A PARTICULAR PURPOSE.  Full license text is available on the following\r
     link: http://www.freertos.org/a00114.html\r
 \r
-    1 tab == 4 spaces!\r
-\r
     ***************************************************************************\r
      *                                                                       *\r
-     *    Having a problem?  Start by reading the FAQ "My application does   *\r
-     *    not run, what could be wrong?"                                     *\r
+     *    FreeRTOS provides completely free yet professionally developed,    *\r
+     *    robust, strictly quality controlled, supported, and cross          *\r
+     *    platform software that is more than just the market leader, it     *\r
+     *    is the industry's de facto standard.                               *\r
      *                                                                       *\r
-     *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
+     *    Help yourself get started quickly while simultaneously helping     *\r
+     *    to support the FreeRTOS project by purchasing a FreeRTOS           *\r
+     *    tutorial book, reference manual, or both:                          *\r
+     *    http://www.FreeRTOS.org/Documentation                              *\r
      *                                                                       *\r
     ***************************************************************************\r
 \r
-    http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
-    license and Real Time Engineers Ltd. contact details.\r
+    http://www.FreeRTOS.org/FAQHelp.html - Having a problem?  Start by reading\r
+    the FAQ page "My application does not run, what could be wrong?".  Have you\r
+    defined configASSERT()?\r
+\r
+    http://www.FreeRTOS.org/support - In return for receiving this top quality\r
+    embedded software for free we request you assist our global community by\r
+    participating in the support forum.\r
+\r
+    http://www.FreeRTOS.org/training - Investing in training allows your team to\r
+    be as productive as possible as early as possible.  Now you can receive\r
+    FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers\r
+    Ltd, and the world's leading authority on the world's leading RTOS.\r
 \r
     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
 \r
-    http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
-    Integrity Systems to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
-    licenses offer ticketed support, indemnification and middleware.\r
+    http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.\r
+    Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.\r
+\r
+    http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High\r
+    Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
+    licenses offer ticketed support, indemnification and commercial middleware.\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
@@ -120,7 +124,8 @@ zero. */
 \r
 /*\r
  * Definition of the queue used by the scheduler.\r
- * Items are queued by copy, not reference.\r
+ * Items are queued by copy, not reference.  See the following link for the\r
+ * rationale: http://www.freertos.org/Embedded-RTOS-Queues.html\r
  */\r
 typedef struct QueueDefinition\r
 {\r
@@ -310,55 +315,68 @@ QueueHandle_t xQueueGenericCreate( const UBaseType_t uxQueueLength, const UBaseT
 Queue_t *pxNewQueue;\r
 size_t xQueueSizeInBytes;\r
 QueueHandle_t xReturn = NULL;\r
+int8_t *pcAllocatedBuffer;\r
 \r
        /* Remove compiler warnings about unused parameters should\r
        configUSE_TRACE_FACILITY not be set to 1. */\r
        ( void ) ucQueueType;\r
 \r
-       /* Allocate the new queue structure. */\r
-       if( uxQueueLength > ( UBaseType_t ) 0 )\r
-       {\r
-               pxNewQueue = ( Queue_t * ) pvPortMalloc( sizeof( Queue_t ) );\r
-               if( pxNewQueue != NULL )\r
-               {\r
-                       /* Create the list of pointers to queue items.  The queue is one byte\r
-                       longer than asked for to make wrap checking easier/faster. */\r
-                       xQueueSizeInBytes = ( size_t ) ( uxQueueLength * uxItemSize ) + ( size_t ) 1; /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\r
+       configASSERT( uxQueueLength > ( UBaseType_t ) 0 );\r
 \r
-                       pxNewQueue->pcHead = ( int8_t * ) pvPortMalloc( xQueueSizeInBytes );\r
-                       if( pxNewQueue->pcHead != NULL )\r
-                       {\r
-                               /* Initialise the queue members as described above where the\r
-                               queue type is defined. */\r
-                               pxNewQueue->uxLength = uxQueueLength;\r
-                               pxNewQueue->uxItemSize = uxItemSize;\r
-                               ( void ) xQueueGenericReset( pxNewQueue, pdTRUE );\r
+       if( uxItemSize == ( UBaseType_t ) 0 )\r
+       {\r
+               /* There is not going to be a queue storage area. */\r
+               xQueueSizeInBytes = ( size_t ) 0;\r
+       }\r
+       else\r
+       {\r
+               /* The queue is one byte longer than asked for to make wrap checking\r
+               easier/faster. */\r
+               xQueueSizeInBytes = ( size_t ) ( uxQueueLength * uxItemSize ) + ( size_t ) 1; /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\r
+       }\r
 \r
-                               #if ( configUSE_TRACE_FACILITY == 1 )\r
-                               {\r
-                                       pxNewQueue->ucQueueType = ucQueueType;\r
-                               }\r
-                               #endif /* configUSE_TRACE_FACILITY */\r
+       /* Allocate the new queue structure and storage area. */\r
+       pcAllocatedBuffer = ( int8_t * ) pvPortMalloc( sizeof( Queue_t ) + xQueueSizeInBytes );\r
 \r
-                               #if( configUSE_QUEUE_SETS == 1 )\r
-                               {\r
-                                       pxNewQueue->pxQueueSetContainer = NULL;\r
-                               }\r
-                               #endif /* configUSE_QUEUE_SETS */\r
+       if( pcAllocatedBuffer != NULL )\r
+       {\r
+               pxNewQueue = ( Queue_t * ) pcAllocatedBuffer; /*lint !e826 MISRA The buffer cannot be too small because it was dimensioned by sizeof( Queue_t ) + xQueueSizeInBytes. */\r
 \r
-                               traceQUEUE_CREATE( pxNewQueue );\r
-                               xReturn = pxNewQueue;\r
-                       }\r
-                       else\r
-                       {\r
-                               traceQUEUE_CREATE_FAILED( ucQueueType );\r
-                               vPortFree( pxNewQueue );\r
-                       }\r
+               if( uxItemSize == ( UBaseType_t ) 0 )\r
+               {\r
+                       /* No RAM was allocated for the queue storage area, but PC head\r
+                       cannot be set to NULL because NULL is used as a key to say the queue\r
+                       is used as a mutex.  Therefore just set pcHead to point to the queue\r
+                       as a benign value that is known to be within the memory map. */\r
+                       pxNewQueue->pcHead = ( int8_t * ) pxNewQueue;\r
                }\r
                else\r
                {\r
-                       mtCOVERAGE_TEST_MARKER();\r
+                       /* Jump past the queue structure to find the location of the queue\r
+                       storage area - adding the padding bytes to get a better alignment. */\r
+                       pxNewQueue->pcHead = pcAllocatedBuffer + sizeof( Queue_t );\r
+               }\r
+\r
+               /* Initialise the queue members as described above where the queue type\r
+               is defined. */\r
+               pxNewQueue->uxLength = uxQueueLength;\r
+               pxNewQueue->uxItemSize = uxItemSize;\r
+               ( void ) xQueueGenericReset( pxNewQueue, pdTRUE );\r
+\r
+               #if ( configUSE_TRACE_FACILITY == 1 )\r
+               {\r
+                       pxNewQueue->ucQueueType = ucQueueType;\r
                }\r
+               #endif /* configUSE_TRACE_FACILITY */\r
+\r
+               #if( configUSE_QUEUE_SETS == 1 )\r
+               {\r
+                       pxNewQueue->pxQueueSetContainer = NULL;\r
+               }\r
+               #endif /* configUSE_QUEUE_SETS */\r
+\r
+               traceQUEUE_CREATE( pxNewQueue );\r
+               xReturn = pxNewQueue;\r
        }\r
        else\r
        {\r
@@ -615,10 +633,10 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
        {\r
                taskENTER_CRITICAL();\r
                {\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
+                       /* Is there room on the queue now?  The running task must be the\r
+                       highest priority task wanting to access the queue.  If the head item\r
+                       in the queue is to be overwritten then it does not matter if the\r
+                       queue is full. */\r
                        if( ( pxQueue->uxMessagesWaiting < pxQueue->uxLength ) || ( xCopyPosition == queueOVERWRITE ) )\r
                        {\r
                                traceQUEUE_SEND( pxQueue );\r
@@ -943,7 +961,7 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
                                        {\r
                                                traceQUEUE_PEEK( pxQueue );\r
 \r
-                                               /* We are not removing the data, so reset our read\r
+                                               /* The data is not being removed, so reset our read\r
                                                pointer. */\r
                                                pxQueue->u.pcReadFrom = pcOriginalReadPosition;\r
 \r
@@ -1074,21 +1092,174 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
                {\r
                        traceQUEUE_SEND_FROM_ISR( pxQueue );\r
 \r
-                       if( prvCopyDataToQueue( pxQueue, pvItemToQueue, xCopyPosition ) != pdFALSE )\r
+                       /* Semaphores use xQueueGiveFromISR(), so pxQueue will not be a\r
+                       semaphore or mutex.  That means prvCopyDataToQueue() cannot result\r
+                       in a task disinheriting a priority and prvCopyDataToQueue() can be\r
+                       called here even though the disinherit function does not check if\r
+                       the scheduler is suspended before accessing the ready lists. */\r
+                       ( void ) prvCopyDataToQueue( pxQueue, pvItemToQueue, xCopyPosition );\r
+\r
+                       /* The event list is not altered if the queue is locked.  This will\r
+                       be done when the queue is unlocked later. */\r
+                       if( pxQueue->xTxLock == queueUNLOCKED )\r
                        {\r
-                               /* This is a special case that can only be executed if a task\r
-                               holds multiple mutexes and then gives the mutexes back in an\r
-                               order that is different to that in which they were taken. */\r
-                               if( pxHigherPriorityTaskWoken != NULL )\r
+                               #if ( configUSE_QUEUE_SETS == 1 )\r
                                {\r
-                                       *pxHigherPriorityTaskWoken = pdTRUE;\r
+                                       if( pxQueue->pxQueueSetContainer != NULL )\r
+                                       {\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
+                                                       if( pxHigherPriorityTaskWoken != NULL )\r
+                                                       {\r
+                                                               *pxHigherPriorityTaskWoken = pdTRUE;\r
+                                                       }\r
+                                                       else\r
+                                                       {\r
+                                                               mtCOVERAGE_TEST_MARKER();\r
+                                                       }\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       mtCOVERAGE_TEST_MARKER();\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\r
+                                                               record that a context switch is required. */\r
+                                                               if( pxHigherPriorityTaskWoken != NULL )\r
+                                                               {\r
+                                                                       *pxHigherPriorityTaskWoken = pdTRUE;\r
+                                                               }\r
+                                                               else\r
+                                                               {\r
+                                                                       mtCOVERAGE_TEST_MARKER();\r
+                                                               }\r
+                                                       }\r
+                                                       else\r
+                                                       {\r
+                                                               mtCOVERAGE_TEST_MARKER();\r
+                                                       }\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       mtCOVERAGE_TEST_MARKER();\r
+                                               }\r
+                                       }\r
                                }\r
-                               else\r
+                               #else /* configUSE_QUEUE_SETS */\r
                                {\r
-                                       mtCOVERAGE_TEST_MARKER();\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
+                                                       else\r
+                                                       {\r
+                                                               mtCOVERAGE_TEST_MARKER();\r
+                                                       }\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       mtCOVERAGE_TEST_MARKER();\r
+                                               }\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               mtCOVERAGE_TEST_MARKER();\r
+                                       }\r
                                }\r
+                               #endif /* configUSE_QUEUE_SETS */\r
+                       }\r
+                       else\r
+                       {\r
+                               /* Increment the lock count so the task that unlocks the queue\r
+                               knows that data was posted while it was locked. */\r
+                               ++( pxQueue->xTxLock );\r
                        }\r
 \r
+                       xReturn = pdPASS;\r
+               }\r
+               else\r
+               {\r
+                       traceQUEUE_SEND_FROM_ISR_FAILED( pxQueue );\r
+                       xReturn = errQUEUE_FULL;\r
+               }\r
+       }\r
+       portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );\r
+\r
+       return xReturn;\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+BaseType_t xQueueGiveFromISR( QueueHandle_t xQueue, BaseType_t * const pxHigherPriorityTaskWoken )\r
+{\r
+BaseType_t xReturn;\r
+UBaseType_t uxSavedInterruptStatus;\r
+Queue_t * const pxQueue = ( Queue_t * ) xQueue;\r
+\r
+       /* Similar to xQueueGenericSendFromISR() but used with semaphores where the\r
+       item size is 0.  Don't directly wake a task that was blocked on a queue\r
+       read, instead return a flag to say whether a context switch is required or\r
+       not (i.e. has a task with a higher priority than us been woken by this\r
+       post). */\r
+\r
+       configASSERT( pxQueue );\r
+\r
+       /* xQueueGenericSendFromISR() should be used instead of xQueueGiveFromISR()\r
+       if the item size is not 0. */\r
+       configASSERT( pxQueue->uxItemSize == 0 );\r
+\r
+       /* Normally a mutex would not be given from an interrupt, and doing so is\r
+       definitely wrong if there is a mutex holder as priority inheritance makes no\r
+       sense for an interrupts, only tasks. */\r
+       configASSERT( !( ( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX ) && ( pxQueue->pxMutexHolder != NULL ) ) );\r
+\r
+       /* RTOS ports that support interrupt nesting have the concept of a maximum\r
+       system call (or maximum API call) interrupt priority.  Interrupts that are\r
+       above the maximum system call priority are kept permanently enabled, even\r
+       when the RTOS kernel is in a critical section, but cannot make any calls to\r
+       FreeRTOS API functions.  If configASSERT() is defined in FreeRTOSConfig.h\r
+       then portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion\r
+       failure if a FreeRTOS API function is called from an interrupt that has been\r
+       assigned a priority above the configured maximum system call priority.\r
+       Only FreeRTOS functions that end in FromISR can be called from interrupts\r
+       that have been assigned a priority at or (logically) below the maximum\r
+       system call     interrupt priority.  FreeRTOS maintains a separate interrupt\r
+       safe API to ensure interrupt entry is as fast and as simple as possible.\r
+       More information (albeit Cortex-M specific) is provided on the following\r
+       link: http://www.freertos.org/RTOS-Cortex-M3-M4.html */\r
+       portASSERT_IF_INTERRUPT_PRIORITY_INVALID();\r
+\r
+       uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();\r
+       {\r
+               /* When the queue is used to implement a semaphore no data is ever\r
+               moved through the queue but it is still valid to see if the queue 'has\r
+               space'. */\r
+               if( pxQueue->uxMessagesWaiting < pxQueue->uxLength )\r
+               {\r
+                       traceQUEUE_SEND_FROM_ISR( pxQueue );\r
+\r
+                       /* A task can only have an inherited priority if it is a mutex\r
+                       holder - and if there is a mutex holder then the mutex cannot be\r
+                       given from an ISR.  As this is the ISR version of the function it\r
+                       can be assumed there is no mutex holder and no need to determine if\r
+                       priority disinheritance is needed.  Simply increase the count of\r
+                       messages (semaphores) available. */\r
+                       ++( pxQueue->uxMessagesWaiting );\r
+\r
                        /* The event list is not altered if the queue is locked.  This will\r
                        be done when the queue is unlocked later. */\r
                        if( pxQueue->xTxLock == queueUNLOCKED )\r
@@ -1097,11 +1268,11 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
                                {\r
                                        if( pxQueue->pxQueueSetContainer != NULL )\r
                                        {\r
-                                               if( prvNotifyQueueSetContainer( pxQueue, xCopyPosition ) == pdTRUE )\r
+                                               if( prvNotifyQueueSetContainer( pxQueue, queueSEND_TO_BACK ) == 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
+                                                       /* The semaphore is a member of a queue set, and\r
+                                                       posting to the queue set caused a higher priority\r
+                                                       task to unblock.  A context switch is required. */\r
                                                        if( pxHigherPriorityTaskWoken != NULL )\r
                                                        {\r
                                                                *pxHigherPriorityTaskWoken = pdTRUE;\r
@@ -1217,8 +1388,8 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
        {\r
                taskENTER_CRITICAL();\r
                {\r
-                       /* Is there data in the queue now?  To be running we must be\r
-                       the highest priority task wanting to access the queue. */\r
+                       /* Is there data in the queue now?  To be running the calling task\r
+                       must be the highest priority task wanting to access the queue. */\r
                        if( pxQueue->uxMessagesWaiting > ( UBaseType_t ) 0 )\r
                        {\r
                                /* Remember the read position in case the queue is only being\r
@@ -1277,8 +1448,6 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
                                        any other tasks waiting for the data. */\r
                                        if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\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
                                                {\r
                                                        /* The task waiting has a higher priority than this task. */\r
@@ -1479,6 +1648,7 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
 \r
        configASSERT( pxQueue );\r
        configASSERT( !( ( pvBuffer == NULL ) && ( pxQueue->uxItemSize != ( UBaseType_t ) 0U ) ) );\r
+       configASSERT( pxQueue->uxItemSize != 0 ); /* Can't peek a semaphore. */\r
 \r
        /* RTOS ports that support interrupt nesting have the concept of a maximum\r
        system call (or maximum API call) interrupt priority.  Interrupts that are\r
@@ -1581,10 +1751,6 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
                vQueueUnregisterQueue( pxQueue );\r
        }\r
        #endif\r
-       if( pxQueue->pcHead != NULL )\r
-       {\r
-               vPortFree( pxQueue->pcHead );\r
-       }\r
        vPortFree( pxQueue );\r
 }\r
 /*-----------------------------------------------------------*/\r
@@ -2237,7 +2403,7 @@ BaseType_t xReturn;
 \r
 #if ( configUSE_TIMERS == 1 )\r
 \r
-       void vQueueWaitForMessageRestricted( QueueHandle_t xQueue, TickType_t xTicksToWait )\r
+       void vQueueWaitForMessageRestricted( QueueHandle_t xQueue, TickType_t xTicksToWait, const BaseType_t xWaitIndefinitely )\r
        {\r
        Queue_t * const pxQueue = ( Queue_t * ) xQueue;\r
 \r
@@ -2259,7 +2425,7 @@ BaseType_t xReturn;
                if( pxQueue->uxMessagesWaiting == ( UBaseType_t ) 0U )\r
                {\r
                        /* There is nothing in the queue, block for the specified period. */\r
-                       vTaskPlaceOnEventListRestricted( &( pxQueue->xTasksWaitingToReceive ), xTicksToWait );\r
+                       vTaskPlaceOnEventListRestricted( &( pxQueue->xTasksWaitingToReceive ), xTicksToWait, xWaitIndefinitely );\r
                }\r
                else\r
                {\r
@@ -2395,15 +2561,23 @@ BaseType_t xReturn;
                if( pxQueueSetContainer->uxMessagesWaiting < pxQueueSetContainer->uxLength )\r
                {\r
                        traceQUEUE_SEND( pxQueueSetContainer );\r
+\r
                        /* The data copied is the handle of the queue that contains data. */\r
                        xReturn = prvCopyDataToQueue( pxQueueSetContainer, &pxQueue, xCopyPosition );\r
 \r
-                       if( listLIST_IS_EMPTY( &( pxQueueSetContainer->xTasksWaitingToReceive ) ) == pdFALSE )\r
+                       if( pxQueueSetContainer->xTxLock == queueUNLOCKED )\r
                        {\r
-                               if( xTaskRemoveFromEventList( &( pxQueueSetContainer->xTasksWaitingToReceive ) ) != pdFALSE )\r
+                               if( listLIST_IS_EMPTY( &( pxQueueSetContainer->xTasksWaitingToReceive ) ) == pdFALSE )\r
                                {\r
-                                       /* The task waiting has a higher priority */\r
-                                       xReturn = pdTRUE;\r
+                                       if( xTaskRemoveFromEventList( &( pxQueueSetContainer->xTasksWaitingToReceive ) ) != pdFALSE )\r
+                                       {\r
+                                               /* The task waiting has a higher priority. */\r
+                                               xReturn = pdTRUE;\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               mtCOVERAGE_TEST_MARKER();\r
+                                       }\r
                                }\r
                                else\r
                                {\r
@@ -2412,7 +2586,7 @@ BaseType_t xReturn;
                        }\r
                        else\r
                        {\r
-                               mtCOVERAGE_TEST_MARKER();\r
+                               ( pxQueueSetContainer->xTxLock )++;\r
                        }\r
                }\r
                else\r