Browse Source

freertos: Revert critical section macro

This commit reverts the previous "taskENTER_CRTIICAL();" so that the argument
is now provided for better code readability. The names of the spinlocks have
also been updated.
Darian Leung 3 years ago
parent
commit
e22e7dd670

+ 27 - 41
components/freertos/FreeRTOS-Kernel/event_groups.c

@@ -45,18 +45,6 @@
 #include "timers.h"
 #include "event_groups.h"
 
-#ifdef ESP_PLATFORM
-#define taskCRITICAL_MUX &pxEventBits->eventGroupMux
-#undef taskENTER_CRITICAL
-#undef taskEXIT_CRITICAL
-#undef taskENTER_CRITICAL_ISR
-#undef taskEXIT_CRITICAL_ISR
-#define taskENTER_CRITICAL( )     portENTER_CRITICAL( taskCRITICAL_MUX )
-#define taskEXIT_CRITICAL( )            portEXIT_CRITICAL( taskCRITICAL_MUX )
-#define taskENTER_CRITICAL_ISR( )     portENTER_CRITICAL_ISR( taskCRITICAL_MUX )
-#define taskEXIT_CRITICAL_ISR( )        portEXIT_CRITICAL_ISR( taskCRITICAL_MUX )
-#endif
-
 /* Lint e961, e750 and e9021 are suppressed as a MISRA exception justified
  * because the MPU ports require MPU_WRAPPERS_INCLUDED_FROM_API_FILE to be defined
  * for the header files above, but not in this file, in order to generate the
@@ -92,7 +80,7 @@ typedef struct EventGroupDef_t
     #endif
 
 #ifdef ESP_PLATFORM
-    portMUX_TYPE eventGroupMux;     //Mutex required due to SMP
+    portMUX_TYPE xEventGroupLock;   /* Spinlock required for SMP critical sections */
 #endif // ESP_PLATFORM
 } EventGroup_t;
 
@@ -150,7 +138,7 @@ static BaseType_t prvTestWaitCondition( const EventBits_t uxCurrentEventBits,
 
             traceEVENT_GROUP_CREATE( pxEventBits );
 #ifdef ESP_PLATFORM
-            portMUX_INITIALIZE( &pxEventBits->eventGroupMux );
+            portMUX_INITIALIZE( &pxEventBits->xEventGroupLock );
 #endif // ESP_PLATFORM
         }
         else
@@ -203,7 +191,7 @@ static BaseType_t prvTestWaitCondition( const EventBits_t uxCurrentEventBits,
             #endif /* configSUPPORT_STATIC_ALLOCATION */
 
 #ifdef ESP_PLATFORM
-            portMUX_INITIALIZE( &pxEventBits->eventGroupMux );
+            portMUX_INITIALIZE( &pxEventBits->xEventGroupLock );
 #endif // ESP_PLATFORM
 
             traceEVENT_GROUP_CREATE( pxEventBits );
@@ -240,7 +228,7 @@ EventBits_t xEventGroupSync( EventGroupHandle_t xEventGroup,
     #endif
 
 #ifdef ESP_PLATFORM // IDF-3755
-    taskENTER_CRITICAL();
+    taskENTER_CRITICAL( &( pxEventBits->xEventGroupLock ) );
 #else
     vTaskSuspendAll();
 #endif // ESP_PLATFORM
@@ -287,7 +275,7 @@ EventBits_t xEventGroupSync( EventGroupHandle_t xEventGroup,
         }
     }
 #ifdef ESP_PLATFORM // IDF-3755
-    taskEXIT_CRITICAL();
+    taskEXIT_CRITICAL( &( pxEventBits->xEventGroupLock ) );
 #else
     xAlreadyYielded = xTaskResumeAll();
 #endif // ESP_PLATFORM
@@ -316,7 +304,7 @@ EventBits_t xEventGroupSync( EventGroupHandle_t xEventGroup,
         if( ( uxReturn & eventUNBLOCKED_DUE_TO_BIT_SET ) == ( EventBits_t ) 0 )
         {
             /* The task timed out, just return the current event bit value. */
-            taskENTER_CRITICAL();
+            taskENTER_CRITICAL( &( pxEventBits->xEventGroupLock ) );
             {
                 uxReturn = pxEventBits->uxEventBits;
 
@@ -333,7 +321,7 @@ EventBits_t xEventGroupSync( EventGroupHandle_t xEventGroup,
                     mtCOVERAGE_TEST_MARKER();
                 }
             }
-            taskEXIT_CRITICAL();
+            taskEXIT_CRITICAL( &( pxEventBits->xEventGroupLock ) );
 
             xTimeoutOccurred = pdTRUE;
         }
@@ -383,7 +371,7 @@ EventBits_t xEventGroupWaitBits( EventGroupHandle_t xEventGroup,
     #endif
 
 #ifdef ESP_PLATFORM // IDF-3755
-    taskENTER_CRITICAL();
+    taskENTER_CRITICAL( &( pxEventBits->xEventGroupLock ) );
 #else
     vTaskSuspendAll();
 #endif // ESP_PLATFORM
@@ -455,7 +443,7 @@ EventBits_t xEventGroupWaitBits( EventGroupHandle_t xEventGroup,
         }
     }
 #ifdef ESP_PLATFORM // IDF-3755
-    taskEXIT_CRITICAL();
+    taskEXIT_CRITICAL( &( pxEventBits->xEventGroupLock ) );
 #else
     xAlreadyYielded = xTaskResumeAll();
 #endif // ESP_PLATFORM
@@ -483,7 +471,7 @@ EventBits_t xEventGroupWaitBits( EventGroupHandle_t xEventGroup,
 
         if( ( uxReturn & eventUNBLOCKED_DUE_TO_BIT_SET ) == ( EventBits_t ) 0 )
         {
-            taskENTER_CRITICAL();
+            taskENTER_CRITICAL( &( pxEventBits->xEventGroupLock ) );
             {
                 /* The task timed out, just return the current event bit value. */
                 uxReturn = pxEventBits->uxEventBits;
@@ -508,7 +496,7 @@ EventBits_t xEventGroupWaitBits( EventGroupHandle_t xEventGroup,
 
                 xTimeoutOccurred = pdTRUE;
             }
-            taskEXIT_CRITICAL();
+            taskEXIT_CRITICAL( &( pxEventBits->xEventGroupLock ) );
         }
         else
         {
@@ -539,7 +527,7 @@ EventBits_t xEventGroupClearBits( EventGroupHandle_t xEventGroup,
     configASSERT( xEventGroup );
     configASSERT( ( uxBitsToClear & eventEVENT_BITS_CONTROL_BYTES ) == 0 );
 
-    taskENTER_CRITICAL();
+    taskENTER_CRITICAL( &( pxEventBits->xEventGroupLock ) );
     {
         traceEVENT_GROUP_CLEAR_BITS( xEventGroup, uxBitsToClear );
 
@@ -550,7 +538,7 @@ EventBits_t xEventGroupClearBits( EventGroupHandle_t xEventGroup,
         /* Clear the bits. */
         pxEventBits->uxEventBits &= ~uxBitsToClear;
     }
-    taskEXIT_CRITICAL();
+    taskEXIT_CRITICAL( &( pxEventBits->xEventGroupLock ) );
 
     return uxReturn;
 }
@@ -606,11 +594,10 @@ EventBits_t xEventGroupSetBits( EventGroupHandle_t xEventGroup,
     pxList = &( pxEventBits->xTasksWaitingForBits );
     pxListEnd = listGET_END_MARKER( pxList ); /*lint !e826 !e740 !e9087 The mini list structure is used as the list end to save RAM.  This is checked and valid. */
 #ifdef ESP_PLATFORM // IDF-3755
-    taskENTER_CRITICAL();
-    /* The critical section above only takes the event groups spinlock. However, we are about to traverse a task list.
-     * Thus we need call the function below to take the task list spinlock located in tasks.c. Not doing so will risk
-     * the task list's being changed while be are traversing it. */
-    vTaskTakeEventListLock();
+    taskENTER_CRITICAL( &( pxEventBits->xEventGroupLock ) );
+    /* We are about to traverse a task list which is a kernel data structure.
+     * Thus we need to call vTaskTakeKernelLock() to take the kernel lock. */
+    vTaskTakeKernelLock();
 #else
     vTaskSuspendAll();
 #endif // ESP_PLATFORM
@@ -686,9 +673,9 @@ EventBits_t xEventGroupSetBits( EventGroupHandle_t xEventGroup,
         pxEventBits->uxEventBits &= ~uxBitsToClear;
     }
 #ifdef ESP_PLATFORM // IDF-3755
-    /* Release the previously held task list spinlock, then release the event group spinlock. */
-    vTaskReleaseEventListLock();
-    taskEXIT_CRITICAL();
+    /* Release the previously taken kernel lock, then release the event group spinlock. */
+    vTaskReleaseKernelLock();
+    taskEXIT_CRITICAL( &( pxEventBits->xEventGroupLock ) );
 #else
     ( void ) xTaskResumeAll();
 #endif // ESP_PLATFORM
@@ -705,12 +692,11 @@ void vEventGroupDelete( EventGroupHandle_t xEventGroup )
     traceEVENT_GROUP_DELETE( xEventGroup );
 
     // IDF-3755
-    taskENTER_CRITICAL();
+    taskENTER_CRITICAL( &( pxEventBits->xEventGroupLock ) );
 #ifdef ESP_PLATFORM
-    /* The critical section above only takes the event groups spinlock. However, we are about to traverse a task list.
-     * Thus we need call the function below to take the task list spinlock located in tasks.c. Not doing so will risk
-     * the task list's being changed while be are traversing it. */
-    vTaskTakeEventListLock();
+    /* We are about to traverse a task list which is a kernel data structure.
+     * Thus we need to call vTaskTakeKernelLock() to take the kernel lock. */
+    vTaskTakeKernelLock();
 #endif
     {
         while( listCURRENT_LIST_LENGTH( pxTasksWaitingForBits ) > ( UBaseType_t ) 0 )
@@ -722,10 +708,10 @@ void vEventGroupDelete( EventGroupHandle_t xEventGroup )
         }
     }
 #ifdef ESP_PLATFORM
-    /* Release the previously held task list spinlock. */
-    vTaskReleaseEventListLock();
+    /* Release the previously taken kernel lock. */
+    vTaskReleaseKernelLock();
 #endif
-    taskEXIT_CRITICAL();
+    taskEXIT_CRITICAL( &( pxEventBits->xEventGroupLock ) );
 
         #if ( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 0 ) )
             {

+ 4 - 4
components/freertos/FreeRTOS-Kernel/include/freertos/task.h

@@ -3391,8 +3391,8 @@ void vTaskPlaceOnEventListRestricted( List_t * const pxEventList,
  * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE.  IT IS AN
  * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
  *
- * This function is a wrapper to take the "xTaskQueueMutex" spinlock of tasks.c.
- * This lock is taken whenver any of the task lists or event lists are
+ * This function is a wrapper to take the "xKernelLock" spinlock of tasks.c.
+ * This lock is taken whenver any of the kernel's data structures are
  * accessed/modified, such as when adding/removing tasks to/from the delayed
  * task list or various event lists.
  *
@@ -3401,8 +3401,8 @@ void vTaskPlaceOnEventListRestricted( List_t * const pxEventList,
  * of delegating the entire responsibility to one of vTask...EventList()
  * functions).
  */
-void vTaskTakeEventListLock( void );
-void vTaskReleaseEventListLock( void );
+void vTaskTakeKernelLock( void );
+void vTaskReleaseKernelLock( void );
 #endif //  ESP_PLATFORM
 
 /*

+ 77 - 89
components/freertos/FreeRTOS-Kernel/queue.c

@@ -47,18 +47,6 @@
     #include "croutine.h"
 #endif
 
-#ifdef ESP_PLATFORM
-#define taskCRITICAL_MUX &((Queue_t *)pxQueue)->mux
-#undef taskENTER_CRITICAL
-#undef taskEXIT_CRITICAL
-#undef taskENTER_CRITICAL_ISR
-#undef taskEXIT_CRITICAL_ISR
-#define taskENTER_CRITICAL( )     portENTER_CRITICAL( taskCRITICAL_MUX )
-#define taskEXIT_CRITICAL( )            portEXIT_CRITICAL( taskCRITICAL_MUX )
-#define taskENTER_CRITICAL_ISR( )     portENTER_CRITICAL_ISR( taskCRITICAL_MUX )
-#define taskEXIT_CRITICAL_ISR( )        portEXIT_CRITICAL_ISR( taskCRITICAL_MUX )
-#endif
-
 /* Lint e9021, e961 and e750 are suppressed as a MISRA exception justified
  * because the MPU ports require MPU_WRAPPERS_INCLUDED_FROM_API_FILE to be defined
  * for the header files above, but not in this file, in order to generate the
@@ -148,7 +136,7 @@ typedef struct QueueDefinition /* The old naming convention is used to prevent b
         uint8_t ucQueueType;
     #endif
 #ifdef ESP_PLATFORM
-    portMUX_TYPE mux;       //Mutex required due to SMP
+    portMUX_TYPE xQueueLock;    /* Spinlock required for SMP critical sections */
 #endif // ESP_PLATFORM
 } xQUEUE;
 
@@ -183,8 +171,8 @@ typedef xQUEUE Queue_t;
  * array position being vacant. */
     PRIVILEGED_DATA QueueRegistryItem_t xQueueRegistry[ configQUEUE_REGISTRY_SIZE ];
 #ifdef ESP_PLATFORM
-    //Need to add queue registry mutex to protect against simultaneous access
-    static portMUX_TYPE queue_registry_spinlock = portMUX_INITIALIZER_UNLOCKED;
+    /* Spinlock required in SMP when accessing the queue registry */
+    static portMUX_TYPE xQueueRegistryLock = portMUX_INITIALIZER_UNLOCKED;
 #endif // ESP_PLATFORM
 #endif /* configQUEUE_REGISTRY_SIZE */
 
@@ -272,7 +260,7 @@ static void prvInitialiseNewQueue( const UBaseType_t uxQueueLength,
  * accessing the queue event lists.
  */
 #define prvLockQueue( pxQueue )                            \
-    taskENTER_CRITICAL();                                  \
+    taskENTER_CRITICAL( &( pxQueue->xQueueLock ) );        \
     {                                                      \
         if( ( pxQueue )->cRxLock == queueUNLOCKED )        \
         {                                                  \
@@ -283,7 +271,7 @@ static void prvInitialiseNewQueue( const UBaseType_t uxQueueLength,
             ( pxQueue )->cTxLock = queueLOCKED_UNMODIFIED; \
         }                                                  \
     }                                                      \
-    taskEXIT_CRITICAL()
+    taskEXIT_CRITICAL( &( pxQueue->xQueueLock ) )
 /*-----------------------------------------------------------*/
 
 BaseType_t xQueueGenericReset( QueueHandle_t xQueue,
@@ -296,11 +284,11 @@ BaseType_t xQueueGenericReset( QueueHandle_t xQueue,
 #ifdef ESP_PLATFORM
     if( xNewQueue == pdTRUE )
     {
-        portMUX_INITIALIZE(&pxQueue->mux);
+        portMUX_INITIALIZE( &( pxQueue->xQueueLock ) );
     }
 #endif // ESP_PLATFORM
 
-    taskENTER_CRITICAL();
+    taskENTER_CRITICAL( &( pxQueue->xQueueLock ) );
     {
         pxQueue->u.xQueue.pcTail = pxQueue->pcHead + ( pxQueue->uxLength * pxQueue->uxItemSize ); /*lint !e9016 Pointer arithmetic allowed on char types, especially when it assists conveying intent. */
         pxQueue->uxMessagesWaiting = ( UBaseType_t ) 0U;
@@ -339,7 +327,7 @@ BaseType_t xQueueGenericReset( QueueHandle_t xQueue,
             vListInitialise( &( pxQueue->xTasksWaitingToReceive ) );
         }
     }
-    taskEXIT_CRITICAL();
+    taskEXIT_CRITICAL( &( pxQueue->xQueueLock ) );
 
     /* A value is returned for calling semantic consistency with previous
      * versions. */
@@ -545,7 +533,7 @@ static void prvInitialiseNewQueue( const UBaseType_t uxQueueLength,
             /* In case this is a recursive mutex. */
             pxNewQueue->u.xSemaphore.uxRecursiveCallCount = 0;
 #ifdef ESP_PLATFORM
-            portMUX_INITIALIZE(&pxNewQueue->mux);
+            portMUX_INITIALIZE( &( pxNewQueue->xQueueLock ) );
 #endif // ESP_PLATFORM
             traceCREATE_MUTEX( pxNewQueue );
 
@@ -613,7 +601,7 @@ static void prvInitialiseNewQueue( const UBaseType_t uxQueueLength,
 #ifdef ESP_PLATFORM
         Queue_t * const pxQueue = (Queue_t *)pxSemaphore;
 #endif
-        taskENTER_CRITICAL();
+        taskENTER_CRITICAL( &( pxQueue->xQueueLock ) );
         {
             if( pxSemaphore->uxQueueType == queueQUEUE_IS_MUTEX )
             {
@@ -624,7 +612,7 @@ static void prvInitialiseNewQueue( const UBaseType_t uxQueueLength,
                 pxReturn = NULL;
             }
         }
-        taskEXIT_CRITICAL();
+        taskEXIT_CRITICAL( &( pxQueue->xQueueLock ) );
 
         return pxReturn;
     } /*lint !e818 xSemaphore cannot be a pointer to const because it is a typedef. */
@@ -844,7 +832,7 @@ BaseType_t xQueueGenericSend( QueueHandle_t xQueue,
      * interest of execution time efficiency. */
     for( ; ; )
     {
-        taskENTER_CRITICAL();
+        taskENTER_CRITICAL( &( pxQueue->xQueueLock ) );
         {
             /* Is there room on the queue now?  The running task must be the
              * highest priority task wanting to access the queue.  If the head item
@@ -950,7 +938,7 @@ BaseType_t xQueueGenericSend( QueueHandle_t xQueue,
                     }
                 #endif /* configUSE_QUEUE_SETS */
 
-                taskEXIT_CRITICAL();
+                taskEXIT_CRITICAL( &( pxQueue->xQueueLock ) );
                 return pdPASS;
             }
             else
@@ -959,7 +947,7 @@ BaseType_t xQueueGenericSend( QueueHandle_t xQueue,
                 {
                     /* The queue was full and no block time is specified (or
                      * the block time has expired) so leave now. */
-                    taskEXIT_CRITICAL();
+                    taskEXIT_CRITICAL( &( pxQueue->xQueueLock ) );
 
                     /* Return to the original privilege level before exiting
                      * the function. */
@@ -980,13 +968,13 @@ BaseType_t xQueueGenericSend( QueueHandle_t xQueue,
                 }
             }
         }
-        taskEXIT_CRITICAL();
+        taskEXIT_CRITICAL( &( pxQueue->xQueueLock ) );
 
         /* Interrupts and other tasks can send to and receive from the queue
          * now the critical section has been exited. */
 
 #ifdef ESP_PLATFORM // IDF-3755
-        taskENTER_CRITICAL();
+        taskENTER_CRITICAL( &( pxQueue->xQueueLock ) );
 #else
         vTaskSuspendAll();
 #endif // ESP_PLATFORM
@@ -1013,7 +1001,7 @@ BaseType_t xQueueGenericSend( QueueHandle_t xQueue,
                  * case the yield will not cause a context switch unless there
                  * is also a higher priority task in the pending ready list. */
 #ifdef ESP_PLATFORM // IDF-3755
-                taskEXIT_CRITICAL();
+                taskEXIT_CRITICAL( &( pxQueue->xQueueLock ) );
 #else
                 if( xTaskResumeAll() == pdFALSE )
 #endif // ESP_PLATFORM
@@ -1027,7 +1015,7 @@ BaseType_t xQueueGenericSend( QueueHandle_t xQueue,
                 /* Try again. */
                 prvUnlockQueue( pxQueue );
 #ifdef ESP_PLATFORM // IDF-3755
-                taskEXIT_CRITICAL();
+                taskEXIT_CRITICAL( &( pxQueue->xQueueLock ) );
 #else
                 ( void ) xTaskResumeAll();
 #endif // ESP_PLATFORM
@@ -1038,7 +1026,7 @@ BaseType_t xQueueGenericSend( QueueHandle_t xQueue,
             /* The timeout has expired. */
             prvUnlockQueue( pxQueue );
 #ifdef ESP_PLATFORM // IDF-3755
-            taskEXIT_CRITICAL();
+            taskEXIT_CRITICAL( &( pxQueue->xQueueLock ) );
 #else
             ( void ) xTaskResumeAll();
 #endif // ESP_PLATFORM
@@ -1086,7 +1074,7 @@ BaseType_t xQueueGenericSendFromISR( QueueHandle_t xQueue,
      * post). */
     uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();
     {
-        taskENTER_CRITICAL_ISR();
+        taskENTER_CRITICAL_ISR( &( pxQueue->xQueueLock ) );
 
         if( ( pxQueue->uxMessagesWaiting < pxQueue->uxLength ) || ( xCopyPosition == queueOVERWRITE ) )
         {
@@ -1200,7 +1188,7 @@ BaseType_t xQueueGenericSendFromISR( QueueHandle_t xQueue,
             xReturn = errQUEUE_FULL;
         }
 
-        taskEXIT_CRITICAL_ISR();
+        taskEXIT_CRITICAL_ISR( &( pxQueue->xQueueLock ) );
     }
     portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );
 
@@ -1250,7 +1238,7 @@ BaseType_t xQueueGiveFromISR( QueueHandle_t xQueue,
 
     uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();
     {
-        taskENTER_CRITICAL_ISR();
+        taskENTER_CRITICAL_ISR( &( pxQueue->xQueueLock ) );
 
         const UBaseType_t uxMessagesWaiting = pxQueue->uxMessagesWaiting;
 
@@ -1369,7 +1357,7 @@ BaseType_t xQueueGiveFromISR( QueueHandle_t xQueue,
             traceQUEUE_GIVE_FROM_ISR_FAILED( pxQueue );
             xReturn = errQUEUE_FULL;
         }
-        taskEXIT_CRITICAL_ISR();
+        taskEXIT_CRITICAL_ISR( &( pxQueue->xQueueLock ) );
     }
     portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );
 
@@ -1404,7 +1392,7 @@ BaseType_t xQueueReceive( QueueHandle_t xQueue,
      * interest of execution time efficiency. */
     for( ; ; )
     {
-        taskENTER_CRITICAL();
+        taskENTER_CRITICAL( &( pxQueue->xQueueLock ) );
         {
             const UBaseType_t uxMessagesWaiting = pxQueue->uxMessagesWaiting;
 
@@ -1436,7 +1424,7 @@ BaseType_t xQueueReceive( QueueHandle_t xQueue,
                     mtCOVERAGE_TEST_MARKER();
                 }
 
-                taskEXIT_CRITICAL();
+                taskEXIT_CRITICAL( &( pxQueue->xQueueLock ) );
                 return pdPASS;
             }
             else
@@ -1445,7 +1433,7 @@ BaseType_t xQueueReceive( QueueHandle_t xQueue,
                 {
                     /* The queue was empty and no block time is specified (or
                      * the block time has expired) so leave now. */
-                    taskEXIT_CRITICAL();
+                    taskEXIT_CRITICAL( &( pxQueue->xQueueLock ) );
                     traceQUEUE_RECEIVE_FAILED( pxQueue );
                     return errQUEUE_EMPTY;
                 }
@@ -1463,13 +1451,13 @@ BaseType_t xQueueReceive( QueueHandle_t xQueue,
                 }
             }
         }
-        taskEXIT_CRITICAL();
+        taskEXIT_CRITICAL( &( pxQueue->xQueueLock ) );
 
         /* Interrupts and other tasks can send to and receive from the queue
          * now the critical section has been exited. */
 
 #ifdef ESP_PLATFORM // IDF-3755
-        taskENTER_CRITICAL();
+        taskENTER_CRITICAL( &( pxQueue->xQueueLock ) );
 #else
         vTaskSuspendAll();
 #endif // ESP_PLATFORM
@@ -1486,7 +1474,7 @@ BaseType_t xQueueReceive( QueueHandle_t xQueue,
                 vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToReceive ), xTicksToWait );
                 prvUnlockQueue( pxQueue );
 #ifdef ESP_PLATFORM // IDF-3755
-                taskEXIT_CRITICAL();
+                taskEXIT_CRITICAL( &( pxQueue->xQueueLock ) );
 #else
                 if( xTaskResumeAll() == pdFALSE )
 #endif // ESP_PLATFORM
@@ -1506,7 +1494,7 @@ BaseType_t xQueueReceive( QueueHandle_t xQueue,
                  * data. */
                 prvUnlockQueue( pxQueue );
 #ifdef ESP_PLATFORM // IDF-3755
-                taskEXIT_CRITICAL();
+                taskEXIT_CRITICAL( &( pxQueue->xQueueLock ) );
 #else
                 ( void ) xTaskResumeAll();
 #endif // ESP_PLATFORM
@@ -1518,7 +1506,7 @@ BaseType_t xQueueReceive( QueueHandle_t xQueue,
              * back and attempt to read the data. */
             prvUnlockQueue( pxQueue );
 #ifdef ESP_PLATFORM // IDF-3755
-            taskEXIT_CRITICAL();
+            taskEXIT_CRITICAL( &( pxQueue->xQueueLock ) );
 #else
             ( void ) xTaskResumeAll();
 #endif // ESP_PLATFORM
@@ -1567,7 +1555,7 @@ BaseType_t xQueueSemaphoreTake( QueueHandle_t xQueue,
      * of execution time efficiency. */
     for( ; ; )
     {
-        taskENTER_CRITICAL();
+        taskENTER_CRITICAL( &( pxQueue->xQueueLock ) );
         {
             /* Semaphores are queues with an item size of 0, and where the
              * number of messages in the queue is the semaphore's count value. */
@@ -1616,7 +1604,7 @@ BaseType_t xQueueSemaphoreTake( QueueHandle_t xQueue,
                     mtCOVERAGE_TEST_MARKER();
                 }
 
-                taskEXIT_CRITICAL();
+                taskEXIT_CRITICAL( &( pxQueue->xQueueLock ) );
                 return pdPASS;
             }
             else
@@ -1634,7 +1622,7 @@ BaseType_t xQueueSemaphoreTake( QueueHandle_t xQueue,
 
                     /* The semaphore count was 0 and no block time is specified
                      * (or the block time has expired) so exit now. */
-                    taskEXIT_CRITICAL();
+                    taskEXIT_CRITICAL( &( pxQueue->xQueueLock ) );
                     traceQUEUE_RECEIVE_FAILED( pxQueue );
                     return errQUEUE_EMPTY;
                 }
@@ -1652,13 +1640,13 @@ BaseType_t xQueueSemaphoreTake( QueueHandle_t xQueue,
                 }
             }
         }
-        taskEXIT_CRITICAL();
+        taskEXIT_CRITICAL( &( pxQueue->xQueueLock ) );
 
         /* Interrupts and other tasks can give to and take from the semaphore
          * now the critical section has been exited. */
 
 #ifdef ESP_PLATFORM // IDF-3755
-        taskENTER_CRITICAL();
+        taskENTER_CRITICAL( &( pxQueue->xQueueLock ) );
 #else
         vTaskSuspendAll();
 #endif // ESP_PLATFORM
@@ -1679,11 +1667,11 @@ BaseType_t xQueueSemaphoreTake( QueueHandle_t xQueue,
                     {
                         if( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX )
                         {
-                            taskENTER_CRITICAL();
+                            taskENTER_CRITICAL( &( pxQueue->xQueueLock ) );
                             {
                                 xInheritanceOccurred = xTaskPriorityInherit( pxQueue->u.xSemaphore.xMutexHolder );
                             }
-                            taskEXIT_CRITICAL();
+                            taskEXIT_CRITICAL( &( pxQueue->xQueueLock ) );
                         }
                         else
                         {
@@ -1695,7 +1683,7 @@ BaseType_t xQueueSemaphoreTake( QueueHandle_t xQueue,
                 vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToReceive ), xTicksToWait );
                 prvUnlockQueue( pxQueue );
 #ifdef ESP_PLATFORM // IDF-3755
-                taskEXIT_CRITICAL();
+                taskEXIT_CRITICAL( &( pxQueue->xQueueLock ) );
 #else
                 if( xTaskResumeAll() == pdFALSE )
 #endif // ESP_PLATFORM
@@ -1715,7 +1703,7 @@ BaseType_t xQueueSemaphoreTake( QueueHandle_t xQueue,
                  * attempt to take the semaphore again. */
                 prvUnlockQueue( pxQueue );
 #ifdef ESP_PLATFORM // IDF-3755
-                taskEXIT_CRITICAL();
+                taskEXIT_CRITICAL( &( pxQueue->xQueueLock ) );
 #else
                 ( void ) xTaskResumeAll();
 #endif // ESP_PLATFORM
@@ -1726,7 +1714,7 @@ BaseType_t xQueueSemaphoreTake( QueueHandle_t xQueue,
             /* Timed out. */
             prvUnlockQueue( pxQueue );
 #ifdef ESP_PLATFORM // IDF-3755
-            taskEXIT_CRITICAL();
+            taskEXIT_CRITICAL( &( pxQueue->xQueueLock ) );
 #else
             ( void ) xTaskResumeAll();
 #endif // ESP_PLATFORM
@@ -1744,7 +1732,7 @@ BaseType_t xQueueSemaphoreTake( QueueHandle_t xQueue,
                          * test the mutex type again to check it is actually a mutex. */
                         if( xInheritanceOccurred != pdFALSE )
                         {
-                            taskENTER_CRITICAL();
+                            taskENTER_CRITICAL( &( pxQueue->xQueueLock ) );
                             {
                                 UBaseType_t uxHighestWaitingPriority;
 
@@ -1756,7 +1744,7 @@ BaseType_t xQueueSemaphoreTake( QueueHandle_t xQueue,
                                 uxHighestWaitingPriority = prvGetDisinheritPriorityAfterTimeout( pxQueue );
                                 vTaskPriorityDisinheritAfterTimeout( pxQueue->u.xSemaphore.xMutexHolder, uxHighestWaitingPriority );
                             }
-                            taskEXIT_CRITICAL();
+                            taskEXIT_CRITICAL( &( pxQueue->xQueueLock ) );
                         }
                     }
                 #endif /* configUSE_MUTEXES */
@@ -1801,7 +1789,7 @@ BaseType_t xQueuePeek( QueueHandle_t xQueue,
      * interest of execution time efficiency. */
     for( ; ; )
     {
-        taskENTER_CRITICAL();
+        taskENTER_CRITICAL( &( pxQueue->xQueueLock ) );
         {
             const UBaseType_t uxMessagesWaiting = pxQueue->uxMessagesWaiting;
 
@@ -1839,7 +1827,7 @@ BaseType_t xQueuePeek( QueueHandle_t xQueue,
                     mtCOVERAGE_TEST_MARKER();
                 }
 
-                taskEXIT_CRITICAL();
+                taskEXIT_CRITICAL( &( pxQueue->xQueueLock ) );
                 return pdPASS;
             }
             else
@@ -1848,7 +1836,7 @@ BaseType_t xQueuePeek( QueueHandle_t xQueue,
                 {
                     /* The queue was empty and no block time is specified (or
                      * the block time has expired) so leave now. */
-                    taskEXIT_CRITICAL();
+                    taskEXIT_CRITICAL( &( pxQueue->xQueueLock ) );
                     traceQUEUE_PEEK_FAILED( pxQueue );
                     return errQUEUE_EMPTY;
                 }
@@ -1867,13 +1855,13 @@ BaseType_t xQueuePeek( QueueHandle_t xQueue,
                 }
             }
         }
-        taskEXIT_CRITICAL();
+        taskEXIT_CRITICAL( &( pxQueue->xQueueLock ) );
 
         /* Interrupts and other tasks can send to and receive from the queue
          * now the critical section has been exited. */
 
 #ifdef ESP_PLATFORM // IDF-3755
-        taskENTER_CRITICAL();
+        taskENTER_CRITICAL( &( pxQueue->xQueueLock ) );
 #else
         vTaskSuspendAll();
 #endif // ESP_PLATFORM
@@ -1890,7 +1878,7 @@ BaseType_t xQueuePeek( QueueHandle_t xQueue,
                 vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToReceive ), xTicksToWait );
                 prvUnlockQueue( pxQueue );
 #ifdef ESP_PLATFORM // IDF-3755
-                taskEXIT_CRITICAL();
+                taskEXIT_CRITICAL( &( pxQueue->xQueueLock ) );
 #else
                 if( xTaskResumeAll() == pdFALSE )
 #endif // ESP_PLATFORM
@@ -1910,7 +1898,7 @@ BaseType_t xQueuePeek( QueueHandle_t xQueue,
                  * state, instead return to try and obtain the data. */
                 prvUnlockQueue( pxQueue );
 #ifdef ESP_PLATFORM // IDF-3755
-                taskEXIT_CRITICAL();
+                taskEXIT_CRITICAL( &( pxQueue->xQueueLock ) );
 #else
                 ( void ) xTaskResumeAll();
 #endif // ESP_PLATFORM
@@ -1922,7 +1910,7 @@ BaseType_t xQueuePeek( QueueHandle_t xQueue,
              * exit, otherwise go back and try to read the data again. */
             prvUnlockQueue( pxQueue );
 #ifdef ESP_PLATFORM // IDF-3755
-            taskEXIT_CRITICAL();
+            taskEXIT_CRITICAL( &( pxQueue->xQueueLock ) );
 #else
             ( void ) xTaskResumeAll();
 #endif // ESP_PLATFORM
@@ -1970,7 +1958,7 @@ BaseType_t xQueueReceiveFromISR( QueueHandle_t xQueue,
 
     uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();
     {
-        taskENTER_CRITICAL_ISR();
+        taskENTER_CRITICAL_ISR( &( pxQueue->xQueueLock ) );
 
         const UBaseType_t uxMessagesWaiting = pxQueue->uxMessagesWaiting;
 
@@ -2029,7 +2017,7 @@ BaseType_t xQueueReceiveFromISR( QueueHandle_t xQueue,
             xReturn = pdFAIL;
             traceQUEUE_RECEIVE_FROM_ISR_FAILED( pxQueue );
         }
-        taskEXIT_CRITICAL_ISR();
+        taskEXIT_CRITICAL_ISR( &( pxQueue->xQueueLock ) );
     }
     portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );
 
@@ -2066,7 +2054,7 @@ BaseType_t xQueuePeekFromISR( QueueHandle_t xQueue,
     portASSERT_IF_INTERRUPT_PRIORITY_INVALID();
 
     uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();
-    taskENTER_CRITICAL_ISR();
+    taskENTER_CRITICAL_ISR( &( pxQueue->xQueueLock ) );
     {
         /* Cannot block in an ISR, so check there is data available. */
         if( pxQueue->uxMessagesWaiting > ( UBaseType_t ) 0 )
@@ -2087,7 +2075,7 @@ BaseType_t xQueuePeekFromISR( QueueHandle_t xQueue,
             traceQUEUE_PEEK_FROM_ISR_FAILED( pxQueue );
         }
     }
-    taskEXIT_CRITICAL_ISR();
+    taskEXIT_CRITICAL_ISR( &( pxQueue->xQueueLock ) );
     portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );
 
     return xReturn;
@@ -2101,11 +2089,11 @@ UBaseType_t uxQueueMessagesWaiting( const QueueHandle_t xQueue )
 
     configASSERT( xQueue );
 
-    taskENTER_CRITICAL();
+    taskENTER_CRITICAL( &( pxQueue->xQueueLock ) );
     {
         uxReturn = ( ( Queue_t * ) xQueue )->uxMessagesWaiting;
     }
-    taskEXIT_CRITICAL();
+    taskEXIT_CRITICAL( &( pxQueue->xQueueLock ) );
 
     return uxReturn;
 } /*lint !e818 Pointer cannot be declared const as xQueue is a typedef not pointer. */
@@ -2118,11 +2106,11 @@ UBaseType_t uxQueueSpacesAvailable( const QueueHandle_t xQueue )
 
     configASSERT( pxQueue );
 
-    taskENTER_CRITICAL();
+    taskENTER_CRITICAL( &( pxQueue->xQueueLock ) );
     {
         uxReturn = pxQueue->uxLength - pxQueue->uxMessagesWaiting;
     }
-    taskEXIT_CRITICAL();
+    taskEXIT_CRITICAL( &( pxQueue->xQueueLock ) );
 
     return uxReturn;
 } /*lint !e818 Pointer cannot be declared const as xQueue is a typedef not pointer. */
@@ -2352,7 +2340,7 @@ static void prvUnlockQueue( Queue_t * const pxQueue )
      * removed from the queue while the queue was locked.  When a queue is
      * locked items can be added or removed, but the event lists cannot be
      * updated. */
-    taskENTER_CRITICAL();
+    taskENTER_CRITICAL( &( pxQueue->xQueueLock ) );
     {
         int8_t cTxLock = pxQueue->cTxLock;
 
@@ -2430,10 +2418,10 @@ static void prvUnlockQueue( Queue_t * const pxQueue )
 
         pxQueue->cTxLock = queueUNLOCKED;
     }
-    taskEXIT_CRITICAL();
+    taskEXIT_CRITICAL( &( pxQueue->xQueueLock ) );
 
     /* Do the same for the Rx lock. */
-    taskENTER_CRITICAL();
+    taskENTER_CRITICAL( &( pxQueue->xQueueLock ) );
     {
         int8_t cRxLock = pxQueue->cRxLock;
 
@@ -2460,14 +2448,14 @@ static void prvUnlockQueue( Queue_t * const pxQueue )
 
         pxQueue->cRxLock = queueUNLOCKED;
     }
-    taskEXIT_CRITICAL();
+    taskEXIT_CRITICAL( &( pxQueue->xQueueLock ) );
 }
 /*-----------------------------------------------------------*/
 
 static BaseType_t prvIsQueueEmpty( const Queue_t * pxQueue )
 {
     BaseType_t xReturn;
-    taskENTER_CRITICAL();
+    taskENTER_CRITICAL( &( ( ( Queue_t * ) pxQueue )->xQueueLock ) );
     {
         if( pxQueue->uxMessagesWaiting == ( UBaseType_t ) 0 )
         {
@@ -2478,7 +2466,7 @@ static BaseType_t prvIsQueueEmpty( const Queue_t * pxQueue )
             xReturn = pdFALSE;
         }
     }
-    taskEXIT_CRITICAL();
+    taskEXIT_CRITICAL( &( ( ( Queue_t * ) pxQueue )->xQueueLock ) );
 
     return xReturn;
 }
@@ -2837,7 +2825,7 @@ BaseType_t xQueueIsQueueFullFromISR( const QueueHandle_t xQueue )
     {
         UBaseType_t ux;
 
-        portENTER_CRITICAL(&queue_registry_spinlock);
+        taskENTER_CRITICAL( &xQueueRegistryLock );
         /* See if there is an empty space in the registry.  A NULL name denotes
          * a free slot. */
         for( ux = ( UBaseType_t ) 0U; ux < ( UBaseType_t ) configQUEUE_REGISTRY_SIZE; ux++ )
@@ -2856,7 +2844,7 @@ BaseType_t xQueueIsQueueFullFromISR( const QueueHandle_t xQueue )
                 mtCOVERAGE_TEST_MARKER();
             }
         }
-        portEXIT_CRITICAL(&queue_registry_spinlock);
+        taskEXIT_CRITICAL( &xQueueRegistryLock );
     }
 
 #endif /* configQUEUE_REGISTRY_SIZE */
@@ -2869,7 +2857,7 @@ BaseType_t xQueueIsQueueFullFromISR( const QueueHandle_t xQueue )
         UBaseType_t ux;
         const char * pcReturn = NULL; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
 
-        portENTER_CRITICAL(&queue_registry_spinlock);
+        taskENTER_CRITICAL( &xQueueRegistryLock );
 
         /* Note there is nothing here to protect against another task adding or
          * removing entries from the registry while it is being searched. */
@@ -2886,7 +2874,7 @@ BaseType_t xQueueIsQueueFullFromISR( const QueueHandle_t xQueue )
                 mtCOVERAGE_TEST_MARKER();
             }
         }
-        portEXIT_CRITICAL(&queue_registry_spinlock);
+        taskEXIT_CRITICAL( &xQueueRegistryLock );
 
         return pcReturn;
     } /*lint !e818 xQueue cannot be a pointer to const because it is a typedef. */
@@ -2900,7 +2888,7 @@ BaseType_t xQueueIsQueueFullFromISR( const QueueHandle_t xQueue )
     {
         UBaseType_t ux;
 
-        portENTER_CRITICAL(&queue_registry_spinlock);
+        taskENTER_CRITICAL( &xQueueRegistryLock );
 
         /* See if the handle of the queue being unregistered in actually in the
          * registry. */
@@ -2922,7 +2910,7 @@ BaseType_t xQueueIsQueueFullFromISR( const QueueHandle_t xQueue )
                 mtCOVERAGE_TEST_MARKER();
             }
         }
-        portEXIT_CRITICAL(&queue_registry_spinlock);
+        taskEXIT_CRITICAL( &xQueueRegistryLock );
 
     } /*lint !e818 xQueue could not be pointer to const because it is a typedef. */
 
@@ -2993,7 +2981,7 @@ BaseType_t xQueueIsQueueFullFromISR( const QueueHandle_t xQueue )
         Queue_t * pxQueue = (Queue_t * )xQueueOrSemaphore;
 #endif
 
-        taskENTER_CRITICAL();
+        taskENTER_CRITICAL( &( pxQueue->xQueueLock ) );
         {
             if( ( ( Queue_t * ) xQueueOrSemaphore )->pxQueueSetContainer != NULL )
             {
@@ -3012,7 +3000,7 @@ BaseType_t xQueueIsQueueFullFromISR( const QueueHandle_t xQueue )
                 xReturn = pdPASS;
             }
         }
-        taskEXIT_CRITICAL();
+        taskEXIT_CRITICAL( &( pxQueue->xQueueLock ) );
 
         return xReturn;
     }
@@ -3045,12 +3033,12 @@ BaseType_t xQueueIsQueueFullFromISR( const QueueHandle_t xQueue )
 #ifdef ESP_PLATFORM
             Queue_t* pxQueue = (Queue_t*)pxQueueOrSemaphore;
 #endif
-            taskENTER_CRITICAL();
+            taskENTER_CRITICAL( &( pxQueue->xQueueLock ) );
             {
                 /* The queue is no longer contained in the set. */
                 pxQueueOrSemaphore->pxQueueSetContainer = NULL;
             }
-            taskEXIT_CRITICAL();
+            taskEXIT_CRITICAL( &( pxQueue->xQueueLock ) );
             xReturn = pdPASS;
         }
 
@@ -3103,7 +3091,7 @@ BaseType_t xQueueIsQueueFullFromISR( const QueueHandle_t xQueue )
         configASSERT( pxQueueSetContainer ); /* LCOV_EXCL_BR_LINE */
 
         //Acquire the Queue set's spinlock
-        portENTER_CRITICAL(&(pxQueueSetContainer->mux));
+        taskENTER_CRITICAL( &( pxQueueSetContainer->xQueueLock ) );
 
         configASSERT( pxQueueSetContainer->uxMessagesWaiting < pxQueueSetContainer->uxLength );
 
@@ -3146,7 +3134,7 @@ BaseType_t xQueueIsQueueFullFromISR( const QueueHandle_t xQueue )
         }
 
         //Release the Queue set's spinlock
-        portEXIT_CRITICAL(&(pxQueueSetContainer->mux));
+        taskEXIT_CRITICAL( &( pxQueueSetContainer->xQueueLock ) );
 
         return xReturn;
     }

+ 15 - 28
components/freertos/FreeRTOS-Kernel/stream_buffer.c

@@ -45,18 +45,6 @@
 #include "task.h"
 #include "stream_buffer.h"
 
-#ifdef ESP_PLATFORM
-#define taskCRITICAL_MUX &pxStreamBuffer->xStreamBufferMux
-#undef taskENTER_CRITICAL
-#undef taskEXIT_CRITICAL
-#undef taskENTER_CRITICAL_ISR
-#undef taskEXIT_CRITICAL_ISR
-#define taskENTER_CRITICAL( )     portENTER_CRITICAL( taskCRITICAL_MUX )
-#define taskEXIT_CRITICAL( )            portEXIT_CRITICAL( taskCRITICAL_MUX )
-#define taskENTER_CRITICAL_ISR( )     portENTER_CRITICAL_ISR( taskCRITICAL_MUX )
-#define taskEXIT_CRITICAL_ISR( )        portEXIT_CRITICAL_ISR( taskCRITICAL_MUX )
-#endif
-
 #if ( configUSE_TASK_NOTIFICATIONS != 1 )
     #error configUSE_TASK_NOTIFICATIONS must be set to 1 to build stream_buffer.c
 #endif
@@ -75,7 +63,7 @@
 #ifndef sbRECEIVE_COMPLETED
 #ifdef ESP_PLATFORM // IDF-3775
     #define sbRECEIVE_COMPLETED( pxStreamBuffer )                         \
-    taskENTER_CRITICAL();                                                 \
+    taskENTER_CRITICAL( &( pxStreamBuffer->xStreamBufferLock ) );         \
     {                                                                     \
         if( ( pxStreamBuffer )->xTaskWaitingToSend != NULL )              \
         {                                                                 \
@@ -85,7 +73,7 @@
             ( pxStreamBuffer )->xTaskWaitingToSend = NULL;                \
         }                                                                 \
     }                                                                     \
-    taskEXIT_CRITICAL();
+    taskEXIT_CRITICAL( &( pxStreamBuffer->xStreamBufferLock ) );
 #else
     #define sbRECEIVE_COMPLETED( pxStreamBuffer )                         \
     vTaskSuspendAll();                                                    \
@@ -129,7 +117,7 @@
 #ifndef sbSEND_COMPLETED
 #ifdef ESP_PLATFORM // IDF-3755
     #define sbSEND_COMPLETED( pxStreamBuffer )                               \
-    taskENTER_CRITICAL();                                                    \
+    taskENTER_CRITICAL( &( pxStreamBuffer->xStreamBufferLock ) );            \
     {                                                                        \
         if( ( pxStreamBuffer )->xTaskWaitingToReceive != NULL )              \
         {                                                                    \
@@ -139,7 +127,7 @@
             ( pxStreamBuffer )->xTaskWaitingToReceive = NULL;                \
         }                                                                    \
     }                                                                        \
-    taskEXIT_CRITICAL();
+    taskEXIT_CRITICAL( &( pxStreamBuffer->xStreamBufferLock ) );
 #else
     #define sbSEND_COMPLETED( pxStreamBuffer )                               \
     vTaskSuspendAll();                                                       \
@@ -202,8 +190,7 @@ typedef struct StreamBufferDef_t                 /*lint !e9058 Style convention
         UBaseType_t uxStreamBufferNumber; /* Used for tracing purposes. */
     #endif
 #ifdef ESP_PLATFORM
-    /* Mutex required due to SMP. This field shall be the last one of the structure. */
-    portMUX_TYPE xStreamBufferMux;
+    portMUX_TYPE xStreamBufferLock;     /* Spinlock required for SMP critical sections */
 #endif // ESP_PLATFORM
 } StreamBuffer_t;
 
@@ -485,7 +472,7 @@ BaseType_t xStreamBufferReset( StreamBufferHandle_t xStreamBuffer )
     #endif
 
     /* Can only reset a message buffer if there are no tasks blocked on it. */
-    taskENTER_CRITICAL();
+    taskENTER_CRITICAL( &( pxStreamBuffer->xStreamBufferLock ) );
     {
         if( pxStreamBuffer->xTaskWaitingToReceive == NULL )
         {
@@ -520,7 +507,7 @@ BaseType_t xStreamBufferReset( StreamBufferHandle_t xStreamBuffer )
             }
         }
     }
-    taskEXIT_CRITICAL();
+    taskEXIT_CRITICAL( &( pxStreamBuffer->xStreamBufferLock ) );
 
     return xReturn;
 }
@@ -657,7 +644,7 @@ size_t xStreamBufferSend( StreamBufferHandle_t xStreamBuffer,
         {
             /* Wait until the required number of bytes are free in the message
              * buffer. */
-            taskENTER_CRITICAL();
+            taskENTER_CRITICAL( &( pxStreamBuffer->xStreamBufferLock ) );
             {
                 xSpace = xStreamBufferSpacesAvailable( pxStreamBuffer );
 
@@ -672,11 +659,11 @@ size_t xStreamBufferSend( StreamBufferHandle_t xStreamBuffer,
                 }
                 else
                 {
-                    taskEXIT_CRITICAL();
+                    taskEXIT_CRITICAL( &( pxStreamBuffer->xStreamBufferLock ) );
                     break;
                 }
             }
-            taskEXIT_CRITICAL();
+            taskEXIT_CRITICAL( &( pxStreamBuffer->xStreamBufferLock ) );
 
             traceBLOCKING_ON_STREAM_BUFFER_SEND( xStreamBuffer );
             ( void ) xTaskNotifyWait( ( uint32_t ) 0, ( uint32_t ) 0, NULL, xTicksToWait );
@@ -855,7 +842,7 @@ size_t xStreamBufferReceive( StreamBufferHandle_t xStreamBuffer,
     {
         /* Checking if there is data and clearing the notification state must be
          * performed atomically. */
-        taskENTER_CRITICAL();
+        taskENTER_CRITICAL( &( pxStreamBuffer->xStreamBufferLock ) );
         {
             xBytesAvailable = prvBytesInBuffer( pxStreamBuffer );
 
@@ -878,7 +865,7 @@ size_t xStreamBufferReceive( StreamBufferHandle_t xStreamBuffer,
                 mtCOVERAGE_TEST_MARKER();
             }
         }
-        taskEXIT_CRITICAL();
+        taskEXIT_CRITICAL( &( pxStreamBuffer->xStreamBufferLock ) );
 
         if( xBytesAvailable <= xBytesToStoreMessageLength )
         {
@@ -1358,7 +1345,7 @@ static void prvInitialiseNewStreamBuffer( StreamBuffer_t * const pxStreamBuffer,
     pxStreamBuffer->xTriggerLevelBytes = xTriggerLevelBytes;
     pxStreamBuffer->ucFlags = ucFlags;
 #ifdef ESP_PLATFORM
-    portMUX_INITIALIZE( &pxStreamBuffer->xStreamBufferMux );
+    portMUX_INITIALIZE( &( pxStreamBuffer->xStreamBufferLock ) );
 #endif // ESP_PLATFORM
 }
 
@@ -1386,8 +1373,8 @@ static void prvInitialiseNewStreamBuffer( StreamBuffer_t * const pxStreamBuffer,
 
         /* Do not include the spinlock in the part to reset!
          * Thus, make sure the spinlock is the last field of the structure. */
-        _Static_assert( offsetof(StreamBuffer_t, xStreamBufferMux) == sizeof( StreamBuffer_t ) - sizeof(portMUX_TYPE),
-                        "xStreamBufferMux must be the last field of structure StreamBuffer_t" );
+        _Static_assert( offsetof(StreamBuffer_t, xStreamBufferLock) == sizeof( StreamBuffer_t ) - sizeof(portMUX_TYPE),
+                        "xStreamBufferLock must be the last field of structure StreamBuffer_t" );
         const size_t erasable = sizeof( StreamBuffer_t ) - sizeof(portMUX_TYPE);
         ( void ) memset( ( void * ) pxStreamBuffer, 0x00, erasable ); /*lint !e9087 memset() requires void *. */
         pxStreamBuffer->pucBuffer = pucBuffer;

File diff suppressed because it is too large
+ 124 - 131
components/freertos/FreeRTOS-Kernel/tasks.c


+ 19 - 30
components/freertos/FreeRTOS-Kernel/timers.c

@@ -48,18 +48,6 @@
     #error configUSE_TIMERS must be set to 1 to make the xTimerPendFunctionCall() function available.
 #endif
 
-#ifdef ESP_PLATFORM
-#define taskCRITICAL_MUX &xTimerMux
-#undef taskENTER_CRITICAL
-#undef taskEXIT_CRITICAL
-#undef taskENTER_CRITICAL_ISR
-#undef taskEXIT_CRITICAL_ISR
-#define taskENTER_CRITICAL( )     portENTER_CRITICAL( taskCRITICAL_MUX )
-#define taskEXIT_CRITICAL( )            portEXIT_CRITICAL( taskCRITICAL_MUX )
-#define taskENTER_CRITICAL_ISR( )     portENTER_CRITICAL_ISR( taskCRITICAL_MUX )
-#define taskEXIT_CRITICAL_ISR( )        portEXIT_CRITICAL_ISR( taskCRITICAL_MUX )
-#endif
-
 /* Lint e9021, e961 and e750 are suppressed as a MISRA exception justified
  * because the MPU ports require MPU_WRAPPERS_INCLUDED_FROM_API_FILE to be defined
  * for the header files above, but not in this file, in order to generate the
@@ -160,8 +148,9 @@
     PRIVILEGED_DATA static TaskHandle_t xTimerTaskHandle = NULL;
 
 #ifdef ESP_PLATFORM
-/* Mux. We use a single mux for all the timers for now. ToDo: maybe increase granularity here? */
-PRIVILEGED_DATA portMUX_TYPE xTimerMux = portMUX_INITIALIZER_UNLOCKED;
+/* Spinlock required in SMP when accessing the timers. For now we use a single lock
+ * Todo: Each timer could possible have its own lock for increased granularity. */
+PRIVILEGED_DATA portMUX_TYPE xTimerLock = portMUX_INITIALIZER_UNLOCKED;
 #endif // ESP_PLATFORM
 
 /*lint -restore */
@@ -470,7 +459,7 @@ PRIVILEGED_DATA portMUX_TYPE xTimerMux = portMUX_INITIALIZER_UNLOCKED;
         Timer_t * pxTimer = xTimer;
 
         configASSERT( xTimer );
-        taskENTER_CRITICAL();
+        taskENTER_CRITICAL( &xTimerLock );
         {
             if( uxAutoReload != pdFALSE )
             {
@@ -481,7 +470,7 @@ PRIVILEGED_DATA portMUX_TYPE xTimerMux = portMUX_INITIALIZER_UNLOCKED;
                 pxTimer->ucStatus &= ~tmrSTATUS_IS_AUTORELOAD;
             }
         }
-        taskEXIT_CRITICAL();
+        taskEXIT_CRITICAL( &xTimerLock );
     }
 /*-----------------------------------------------------------*/
 
@@ -491,7 +480,7 @@ PRIVILEGED_DATA portMUX_TYPE xTimerMux = portMUX_INITIALIZER_UNLOCKED;
         UBaseType_t uxReturn;
 
         configASSERT( xTimer );
-        taskENTER_CRITICAL( );
+        taskENTER_CRITICAL( &xTimerLock );
         {
             if( ( pxTimer->ucStatus & tmrSTATUS_IS_AUTORELOAD ) == 0 )
             {
@@ -504,7 +493,7 @@ PRIVILEGED_DATA portMUX_TYPE xTimerMux = portMUX_INITIALIZER_UNLOCKED;
                 uxReturn = ( UBaseType_t ) pdTRUE;
             }
         }
-        taskEXIT_CRITICAL();
+        taskEXIT_CRITICAL( &xTimerLock );
 
         return uxReturn;
     }
@@ -616,7 +605,7 @@ PRIVILEGED_DATA portMUX_TYPE xTimerMux = portMUX_INITIALIZER_UNLOCKED;
         BaseType_t xTimerListsWereSwitched;
 
 #ifdef ESP_PLATFORM
-        taskENTER_CRITICAL();
+        taskENTER_CRITICAL( &xTimerLock );
 #else
         vTaskSuspendAll();
 #endif // ESP_PLATFORM
@@ -634,7 +623,7 @@ PRIVILEGED_DATA portMUX_TYPE xTimerMux = portMUX_INITIALIZER_UNLOCKED;
                 if( ( xListWasEmpty == pdFALSE ) && ( xNextExpireTime <= xTimeNow ) )
                 {
 #ifdef ESP_PLATFORM
-                    taskEXIT_CRITICAL();
+                    taskEXIT_CRITICAL( &xTimerLock );
 #else
                     ( void ) xTaskResumeAll();
 #endif // ESP_PLATFORM
@@ -658,7 +647,7 @@ PRIVILEGED_DATA portMUX_TYPE xTimerMux = portMUX_INITIALIZER_UNLOCKED;
                     vQueueWaitForMessageRestricted( xTimerQueue, ( xNextExpireTime - xTimeNow ), xListWasEmpty );
 
 #ifdef ESP_PLATFORM // IDF-3755
-                    taskEXIT_CRITICAL();
+                    taskEXIT_CRITICAL( &xTimerLock );
 #else
                     if( xTaskResumeAll() == pdFALSE )
 #endif // ESP_PLATFORM
@@ -680,7 +669,7 @@ PRIVILEGED_DATA portMUX_TYPE xTimerMux = portMUX_INITIALIZER_UNLOCKED;
             else
             {
 #ifdef ESP_PLATFORM // IDF-3755
-                taskEXIT_CRITICAL();
+                taskEXIT_CRITICAL( &xTimerLock );
 #else
                 ( void ) xTaskResumeAll();
 #endif // ESP_PLATFORM
@@ -999,7 +988,7 @@ PRIVILEGED_DATA portMUX_TYPE xTimerMux = portMUX_INITIALIZER_UNLOCKED;
         /* Check that the list from which active timers are referenced, and the
          * queue used to communicate with the timer service, have been
          * initialised. */
-        taskENTER_CRITICAL();
+        taskENTER_CRITICAL( &xTimerLock );
         {
             if( xTimerQueue == NULL )
             {
@@ -1041,7 +1030,7 @@ PRIVILEGED_DATA portMUX_TYPE xTimerMux = portMUX_INITIALIZER_UNLOCKED;
                 mtCOVERAGE_TEST_MARKER();
             }
         }
-        taskEXIT_CRITICAL();
+        taskEXIT_CRITICAL( &xTimerLock );
     }
 /*-----------------------------------------------------------*/
 
@@ -1053,7 +1042,7 @@ PRIVILEGED_DATA portMUX_TYPE xTimerMux = portMUX_INITIALIZER_UNLOCKED;
         configASSERT( xTimer );
 
         /* Is the timer in the list of active timers? */
-        taskENTER_CRITICAL();
+        taskENTER_CRITICAL( &xTimerLock );
         {
             if( ( pxTimer->ucStatus & tmrSTATUS_IS_ACTIVE ) == 0 )
             {
@@ -1064,7 +1053,7 @@ PRIVILEGED_DATA portMUX_TYPE xTimerMux = portMUX_INITIALIZER_UNLOCKED;
                 xReturn = pdTRUE;
             }
         }
-        taskEXIT_CRITICAL();
+        taskEXIT_CRITICAL( &xTimerLock );
 
         return xReturn;
     } /*lint !e818 Can't be pointer to const due to the typedef. */
@@ -1077,11 +1066,11 @@ PRIVILEGED_DATA portMUX_TYPE xTimerMux = portMUX_INITIALIZER_UNLOCKED;
 
         configASSERT( xTimer );
 
-        taskENTER_CRITICAL();
+        taskENTER_CRITICAL( &xTimerLock );
         {
             pvReturn = pxTimer->pvTimerID;
         }
-        taskEXIT_CRITICAL();
+        taskEXIT_CRITICAL( &xTimerLock );
 
         return pvReturn;
     }
@@ -1094,11 +1083,11 @@ PRIVILEGED_DATA portMUX_TYPE xTimerMux = portMUX_INITIALIZER_UNLOCKED;
 
         configASSERT( xTimer );
 
-        taskENTER_CRITICAL();
+        taskENTER_CRITICAL( &xTimerLock );
         {
             pxTimer->pvTimerID = pvNewID;
         }
-        taskEXIT_CRITICAL();
+        taskEXIT_CRITICAL( &xTimerLock );
     }
 /*-----------------------------------------------------------*/
 

Some files were not shown because too many files changed in this diff