]> git.sur5r.net Git - freertos/commitdiff
Return the lock counts to their original intended behaviour.
authorRichardBarry <RichardBarry@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>
Sat, 29 Mar 2008 20:50:38 +0000 (20:50 +0000)
committerRichardBarry <RichardBarry@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>
Sat, 29 Mar 2008 20:50:38 +0000 (20:50 +0000)
git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@285 1d2547de-c912-0410-9cb9-b8ca96c0e9e2

Source/queue.c

index a591ea86c45b1d15204832060c2d9b6b4c171e51..6927a5af5529b565e22e6490a3a5ed7cc72026e9 100644 (file)
@@ -58,7 +58,9 @@
  *----------------------------------------------------------*/\r
 \r
 /* Constants used with the cRxLock and cTxLock structure members. */\r
-#define queueUNLOCKED  ( ( signed portBASE_TYPE ) -1 )\r
+#define queueUNLOCKED                                                  ( ( signed portBASE_TYPE ) -1 )\r
+#define queueLOCKED_UNMODIFIED                                 ( ( signed portBASE_TYPE ) 0 )\r
+\r
 #define queueERRONEOUS_UNBLOCK                                 ( -1 )\r
 \r
 /* For internal use only. */\r
@@ -177,12 +179,20 @@ static void prvCopyDataFromQueue( xQUEUE * const pxQueue, const void *pvBuffer )
  * Macro to mark a queue as locked.  Locking a queue prevents an ISR from\r
  * accessing the queue event lists.\r
  */\r
-#define prvLockQueue( pxQueue )                        \\r
-{                                                                              \\r
-       taskENTER_CRITICAL();                           \\r
-               ++( pxQueue->xRxLock );                 \\r
-               ++( pxQueue->xTxLock );                 \\r
-       taskEXIT_CRITICAL();                            \\r
+#define prvLockQueue( pxQueue )                                                        \\r
+{                                                                                                              \\r
+       taskENTER_CRITICAL();                                                           \\r
+       {                                                                                                       \\r
+               if( pxQueue->xRxLock == queueUNLOCKED )                 \\r
+               {                                                                                               \\r
+                       pxQueue->xRxLock = queueLOCKED_UNMODIFIED;      \\r
+               }                                                                                               \\r
+               if( pxQueue->xTxLock == queueUNLOCKED )                 \\r
+               {                                                                                               \\r
+                       pxQueue->xTxLock = queueLOCKED_UNMODIFIED;      \\r
+               }                                                                                               \\r
+       }                                                                                                       \\r
+       taskEXIT_CRITICAL();                                                            \\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
@@ -1134,13 +1144,9 @@ static void prvUnlockQueue( xQueueHandle pxQueue )
        updated. */\r
        taskENTER_CRITICAL();\r
        {\r
-               --( pxQueue->xTxLock );\r
-\r
                /* See if data was added to the queue while it was locked. */\r
-               if( pxQueue->xTxLock > queueUNLOCKED )\r
+               while( pxQueue->xTxLock > queueLOCKED_UNMODIFIED )\r
                {\r
-                       pxQueue->xTxLock = queueUNLOCKED;\r
-\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 ) ) )\r
@@ -1153,28 +1159,40 @@ static void prvUnlockQueue( xQueueHandle pxQueue )
                                        context switch is required. */\r
                                        vTaskMissedYield();\r
                                }\r
-                       }                       \r
+\r
+                               --( pxQueue->xTxLock );\r
+                       }\r
+                       else\r
+                       {\r
+                               break;\r
+                       }\r
                }\r
+\r
+               pxQueue->xTxLock = queueUNLOCKED;\r
        }\r
        taskEXIT_CRITICAL();\r
 \r
        /* Do the same for the Rx lock. */\r
        taskENTER_CRITICAL();\r
        {\r
-               --( pxQueue->xRxLock );\r
-\r
-               if( pxQueue->xRxLock > queueUNLOCKED )\r
+               while( pxQueue->xRxLock > queueLOCKED_UNMODIFIED )\r
                {\r
-                       pxQueue->xRxLock = queueUNLOCKED;\r
-\r
                        if( !listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) )\r
                        {\r
                                if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE )\r
                                {\r
                                        vTaskMissedYield();\r
                                }\r
-                       }                       \r
+\r
+                               --( pxQueue->xRxLock );\r
+                       }\r
+                       else\r
+                       {\r
+                               break;\r
+                       }\r
                }\r
+\r
+               pxQueue->xRxLock = queueUNLOCKED;\r
        }\r
        taskEXIT_CRITICAL();\r
 }\r