From 0d54d1c4dc6ce064b252dc246cf1691b0afcf627 Mon Sep 17 00:00:00 2001
From: Richard Barry <ribarry@amazon.com>
Date: Wed, 29 Jan 2020 19:52:38 +0000
Subject: [PATCH] Correct an err in queue.c introduced when previously updating
 behaviour when queue sets are used in combination with queue overwrites.

---
 .../CORTEX_A9_Zynq_ZC702/RTOSDemo/.project    | 55 +++++++++++--------
 .../RTOSDemo/src/Full_Demo/main_full.c        | 20 ++++++-
 .../CORTEX_A9_Zynq_ZC702/RTOSDemo/src/main.c  |  7 +++
 FreeRTOS/Source/queue.c                       | 27 ++++-----
 4 files changed, 68 insertions(+), 41 deletions(-)

diff --git a/FreeRTOS/Demo/CORTEX_A9_Zynq_ZC702/RTOSDemo/.project b/FreeRTOS/Demo/CORTEX_A9_Zynq_ZC702/RTOSDemo/.project
index 783ec01123..0d8df7eec6 100644
--- a/FreeRTOS/Demo/CORTEX_A9_Zynq_ZC702/RTOSDemo/.project
+++ b/FreeRTOS/Demo/CORTEX_A9_Zynq_ZC702/RTOSDemo/.project
@@ -219,7 +219,7 @@
 			</matcher>
 		</filter>
 		<filter>
-			<id>1528755597221</id>
+			<id>1580324678127</id>
 			<name>src/Full_Demo/Standard-Demo-Tasks/Minimal</name>
 			<type>5</type>
 			<matcher>
@@ -228,7 +228,7 @@
 			</matcher>
 		</filter>
 		<filter>
-			<id>1528755597236</id>
+			<id>1580324678132</id>
 			<name>src/Full_Demo/Standard-Demo-Tasks/Minimal</name>
 			<type>5</type>
 			<matcher>
@@ -237,7 +237,7 @@
 			</matcher>
 		</filter>
 		<filter>
-			<id>1528755597244</id>
+			<id>1580324678137</id>
 			<name>src/Full_Demo/Standard-Demo-Tasks/Minimal</name>
 			<type>5</type>
 			<matcher>
@@ -246,7 +246,7 @@
 			</matcher>
 		</filter>
 		<filter>
-			<id>1528755597250</id>
+			<id>1580324678144</id>
 			<name>src/Full_Demo/Standard-Demo-Tasks/Minimal</name>
 			<type>5</type>
 			<matcher>
@@ -255,7 +255,7 @@
 			</matcher>
 		</filter>
 		<filter>
-			<id>1528755597254</id>
+			<id>1580324678149</id>
 			<name>src/Full_Demo/Standard-Demo-Tasks/Minimal</name>
 			<type>5</type>
 			<matcher>
@@ -264,7 +264,7 @@
 			</matcher>
 		</filter>
 		<filter>
-			<id>1528755597258</id>
+			<id>1580324678155</id>
 			<name>src/Full_Demo/Standard-Demo-Tasks/Minimal</name>
 			<type>5</type>
 			<matcher>
@@ -273,7 +273,7 @@
 			</matcher>
 		</filter>
 		<filter>
-			<id>1528755597263</id>
+			<id>1580324678160</id>
 			<name>src/Full_Demo/Standard-Demo-Tasks/Minimal</name>
 			<type>5</type>
 			<matcher>
@@ -282,7 +282,7 @@
 			</matcher>
 		</filter>
 		<filter>
-			<id>1528755597267</id>
+			<id>1580324678165</id>
 			<name>src/Full_Demo/Standard-Demo-Tasks/Minimal</name>
 			<type>5</type>
 			<matcher>
@@ -291,7 +291,7 @@
 			</matcher>
 		</filter>
 		<filter>
-			<id>1528755597271</id>
+			<id>1580324678171</id>
 			<name>src/Full_Demo/Standard-Demo-Tasks/Minimal</name>
 			<type>5</type>
 			<matcher>
@@ -300,7 +300,7 @@
 			</matcher>
 		</filter>
 		<filter>
-			<id>1528755597278</id>
+			<id>1580324678176</id>
 			<name>src/Full_Demo/Standard-Demo-Tasks/Minimal</name>
 			<type>5</type>
 			<matcher>
@@ -309,7 +309,7 @@
 			</matcher>
 		</filter>
 		<filter>
-			<id>1528755597282</id>
+			<id>1580324678196</id>
 			<name>src/Full_Demo/Standard-Demo-Tasks/Minimal</name>
 			<type>5</type>
 			<matcher>
@@ -318,7 +318,7 @@
 			</matcher>
 		</filter>
 		<filter>
-			<id>1528755597288</id>
+			<id>1580324678207</id>
 			<name>src/Full_Demo/Standard-Demo-Tasks/Minimal</name>
 			<type>5</type>
 			<matcher>
@@ -327,7 +327,7 @@
 			</matcher>
 		</filter>
 		<filter>
-			<id>1528755597292</id>
+			<id>1580324678218</id>
 			<name>src/Full_Demo/Standard-Demo-Tasks/Minimal</name>
 			<type>5</type>
 			<matcher>
@@ -336,7 +336,7 @@
 			</matcher>
 		</filter>
 		<filter>
-			<id>1528755597302</id>
+			<id>1580324678227</id>
 			<name>src/Full_Demo/Standard-Demo-Tasks/Minimal</name>
 			<type>5</type>
 			<matcher>
@@ -345,7 +345,7 @@
 			</matcher>
 		</filter>
 		<filter>
-			<id>1528755597306</id>
+			<id>1580324678238</id>
 			<name>src/Full_Demo/Standard-Demo-Tasks/Minimal</name>
 			<type>5</type>
 			<matcher>
@@ -354,7 +354,7 @@
 			</matcher>
 		</filter>
 		<filter>
-			<id>1528755597310</id>
+			<id>1580324678249</id>
 			<name>src/Full_Demo/Standard-Demo-Tasks/Minimal</name>
 			<type>5</type>
 			<matcher>
@@ -363,7 +363,7 @@
 			</matcher>
 		</filter>
 		<filter>
-			<id>1528755597314</id>
+			<id>1580324678260</id>
 			<name>src/Full_Demo/Standard-Demo-Tasks/Minimal</name>
 			<type>5</type>
 			<matcher>
@@ -372,7 +372,7 @@
 			</matcher>
 		</filter>
 		<filter>
-			<id>1528755597318</id>
+			<id>1580324678271</id>
 			<name>src/Full_Demo/Standard-Demo-Tasks/Minimal</name>
 			<type>5</type>
 			<matcher>
@@ -381,7 +381,7 @@
 			</matcher>
 		</filter>
 		<filter>
-			<id>1528755597321</id>
+			<id>1580324678282</id>
 			<name>src/Full_Demo/Standard-Demo-Tasks/Minimal</name>
 			<type>5</type>
 			<matcher>
@@ -390,7 +390,7 @@
 			</matcher>
 		</filter>
 		<filter>
-			<id>1528755597325</id>
+			<id>1580324678293</id>
 			<name>src/Full_Demo/Standard-Demo-Tasks/Minimal</name>
 			<type>5</type>
 			<matcher>
@@ -399,7 +399,7 @@
 			</matcher>
 		</filter>
 		<filter>
-			<id>1528755597330</id>
+			<id>1580324678305</id>
 			<name>src/Full_Demo/Standard-Demo-Tasks/Minimal</name>
 			<type>5</type>
 			<matcher>
@@ -408,7 +408,7 @@
 			</matcher>
 		</filter>
 		<filter>
-			<id>1528755597334</id>
+			<id>1580324678315</id>
 			<name>src/Full_Demo/Standard-Demo-Tasks/Minimal</name>
 			<type>5</type>
 			<matcher>
@@ -417,7 +417,7 @@
 			</matcher>
 		</filter>
 		<filter>
-			<id>1528755597338</id>
+			<id>1580324678325</id>
 			<name>src/Full_Demo/Standard-Demo-Tasks/Minimal</name>
 			<type>5</type>
 			<matcher>
@@ -425,6 +425,15 @@
 				<arguments>1.0-name-matches-false-false-StreamBufferInterrupt.c</arguments>
 			</matcher>
 		</filter>
+		<filter>
+			<id>1580324678334</id>
+			<name>src/Full_Demo/Standard-Demo-Tasks/Minimal</name>
+			<type>5</type>
+			<matcher>
+				<id>org.eclipse.ui.ide.multiFilter</id>
+				<arguments>1.0-name-matches-false-false-QueueSet.c</arguments>
+			</matcher>
+		</filter>
 		<filter>
 			<id>1461598705091</id>
 			<name>src/lwIP_Demo/lwip-1.4.0/src/core</name>
diff --git a/FreeRTOS/Demo/CORTEX_A9_Zynq_ZC702/RTOSDemo/src/Full_Demo/main_full.c b/FreeRTOS/Demo/CORTEX_A9_Zynq_ZC702/RTOSDemo/src/Full_Demo/main_full.c
index 9c13342698..3200bf6a64 100644
--- a/FreeRTOS/Demo/CORTEX_A9_Zynq_ZC702/RTOSDemo/src/Full_Demo/main_full.c
+++ b/FreeRTOS/Demo/CORTEX_A9_Zynq_ZC702/RTOSDemo/src/Full_Demo/main_full.c
@@ -114,6 +114,7 @@
 #include "StreamBufferDemo.h"
 #include "StreamBufferInterrupt.h"
 #include "MessageBufferAMP.h"
+#include "QueueSet.h"
 
 
 /* Priorities for the demo application tasks. */
@@ -233,6 +234,12 @@ void main_full( void )
 	vStartStreamBufferInterruptDemo();
 	vStartMessageBufferAMPTasks( mainMESSAGE_BUFFER_STACK_SIZE );
 
+	#if( configUSE_QUEUE_SETS == 1 )
+	{
+		vStartQueueSetTasks();
+	}
+	#endif
+
 	/* Start the tasks that implements the command console on the UART, as
 	described above. */
 	vUARTCommandConsoleStart( mainUART_COMMAND_CONSOLE_STACK_SIZE, mainUART_COMMAND_CONSOLE_TASK_PRIORITY );
@@ -403,17 +410,26 @@ unsigned long ulErrorFound = pdFALSE;
 			ulErrorFound |= 1UL << 20UL;
 		}
 
+		#if( configUSE_QUEUE_SETS == 1 )
+		{
+			if( xAreQueueSetTasksStillRunning() != pdPASS )
+			{
+				ulErrorFound |= 1UL << 21UL;
+			}
+		}
+		#endif
+
 		/* Check that the register test 1 task is still running. */
 		if( ulLastRegTest1Value == ulRegTest1LoopCounter )
 		{
-			ulErrorFound |= 1UL << 21UL;
+			ulErrorFound |= 1UL << 22UL;
 		}
 		ulLastRegTest1Value = ulRegTest1LoopCounter;
 
 		/* Check that the register test 2 task is still running. */
 		if( ulLastRegTest2Value == ulRegTest2LoopCounter )
 		{
-			ulErrorFound |= 1UL << 22UL;
+			ulErrorFound |= 1UL << 23UL;
 		}
 		ulLastRegTest2Value = ulRegTest2LoopCounter;
 
diff --git a/FreeRTOS/Demo/CORTEX_A9_Zynq_ZC702/RTOSDemo/src/main.c b/FreeRTOS/Demo/CORTEX_A9_Zynq_ZC702/RTOSDemo/src/main.c
index adf6f1d45f..22950ff1a8 100644
--- a/FreeRTOS/Demo/CORTEX_A9_Zynq_ZC702/RTOSDemo/src/main.c
+++ b/FreeRTOS/Demo/CORTEX_A9_Zynq_ZC702/RTOSDemo/src/main.c
@@ -78,6 +78,7 @@
 #include "IntSemTest.h"
 #include "StreamBufferInterrupt.h"
 #include "StreamBufferDemo.h"
+#include "QueueSet.h"
 
 /* Xilinx includes. */
 #include "platform.h"
@@ -303,6 +304,12 @@ void vApplicationTickHook( void )
 		a stream being sent from an interrupt to a task. */
 		vBasicStreamBufferSendFromISR();
 
+		#if( configUSE_QUEUE_SETS == 1 )
+		{
+			vQueueSetAccessQueueSetFromISR();
+		}
+		#endif
+
 		/* Test flop alignment in interrupts - calling printf from an interrupt
 		is BAD! */
 		#if( configASSERT_DEFINED == 1 )
diff --git a/FreeRTOS/Source/queue.c b/FreeRTOS/Source/queue.c
index 103718dba8..eacc69c3fb 100644
--- a/FreeRTOS/Source/queue.c
+++ b/FreeRTOS/Source/queue.c
@@ -983,24 +983,23 @@ Queue_t * const pxQueue = xQueue;
 		if( ( pxQueue->uxMessagesWaiting < pxQueue->uxLength ) || ( xCopyPosition == queueOVERWRITE ) )
 		{
 			const int8_t cTxLock = pxQueue->cTxLock;
+			const UBaseType_t uxPreviousMessagesWaiting = pxQueue->uxMessagesWaiting;
 
 			traceQUEUE_SEND_FROM_ISR( pxQueue );
 
+			/* Semaphores use xQueueGiveFromISR(), so pxQueue will not be a
+			semaphore or mutex.  That means prvCopyDataToQueue() cannot result
+			in a task disinheriting a priority and prvCopyDataToQueue() can be
+			called here even though the disinherit function does not check if
+			the scheduler is suspended before accessing the ready lists. */
+			( void ) prvCopyDataToQueue( pxQueue, pvItemToQueue, xCopyPosition );
+
 			/* The event list is not altered if the queue is locked.  This will
 			be done when the queue is unlocked later. */
 			if( cTxLock == queueUNLOCKED )
 			{
 				#if ( configUSE_QUEUE_SETS == 1 )
 				{
-					const UBaseType_t uxPreviousMessagesWaiting = pxQueue->uxMessagesWaiting;
-
-					/* Semaphores use xQueueGiveFromISR(), so pxQueue will not be a
-					semaphore or mutex.  That means prvCopyDataToQueue() cannot result
-					in a task disinheriting a priority and prvCopyDataToQueue() can be
-					called here even though the disinherit function does not check if
-					the scheduler is suspended before accessing the ready lists. */
-					( void ) prvCopyDataToQueue( pxQueue, pvItemToQueue, xCopyPosition );
-
 					if( pxQueue->pxQueueSetContainer != NULL )
 					{
 						if( ( xCopyPosition == queueOVERWRITE ) && ( uxPreviousMessagesWaiting != ( UBaseType_t ) 0 ) )
@@ -1059,13 +1058,6 @@ Queue_t * const pxQueue = xQueue;
 				}
 				#else /* configUSE_QUEUE_SETS */
 				{
-					/* Semaphores use xQueueGiveFromISR(), so pxQueue will not be a
-					semaphore or mutex.  That means prvCopyDataToQueue() cannot result
-					in a task disinheriting a priority and prvCopyDataToQueue() can be
-					called here even though the disinherit function does not check if
-					the scheduler is suspended before accessing the ready lists. */
-					( void ) prvCopyDataToQueue( pxQueue, pvItemToQueue, xCopyPosition );
-
 					if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )
 					{
 						if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )
@@ -1090,6 +1082,9 @@ Queue_t * const pxQueue = xQueue;
 					{
 						mtCOVERAGE_TEST_MARKER();
 					}
+					
+					/* Not used in this path. */
+					( void ) uxPreviousMessagesWaiting;
 				}
 				#endif /* configUSE_QUEUE_SETS */
 			}