mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-07-04 11:27:16 -04:00
change(freertos/smp): Update queue.c locking
Updated queue.c to use granular locking - Added xTaskSpinlock and xISRSpinlock - Replaced critical section macros with data group critical section macros such as taskENTER/EXIT_CRITICAL/_FROM_ISR() with queueENTER/EXIT_CRITICAL_FROM_ISR(). - Added vQueueEnterCritical/FromISR() and vQueueExitCritical/FromISR() which map to the data group critical section macros. - Added prvLockQueueForTasks() and prvUnlockQueueForTasks() as the granular locking equivalents to prvLockQueue() and prvUnlockQueue() respectively Co-authored-by: Sudeep Mohanty <sudeep.mohanty@espressif.com>
This commit is contained in:
parent
25c74e3d4b
commit
b256ca88b1
|
@ -3321,6 +3321,10 @@ typedef struct xSTATIC_QUEUE
|
|||
UBaseType_t uxDummy8;
|
||||
uint8_t ucDummy9;
|
||||
#endif
|
||||
|
||||
#if ( ( portUSING_GRANULAR_LOCKS == 1 ) && ( configNUMBER_OF_CORES > 1 ) )
|
||||
portSPINLOCK_TYPE xDummySpinlock[ 2 ];
|
||||
#endif /* #if ( ( portUSING_GRANULAR_LOCKS == 1 ) && ( configNUMBER_OF_CORES > 1 ) ) */
|
||||
} StaticQueue_t;
|
||||
typedef StaticQueue_t StaticSemaphore_t;
|
||||
|
||||
|
|
277
queue.c
277
queue.c
|
@ -133,6 +133,11 @@ typedef struct QueueDefinition /* The old naming convention is used to prevent b
|
|||
UBaseType_t uxQueueNumber;
|
||||
uint8_t ucQueueType;
|
||||
#endif
|
||||
|
||||
#if ( ( portUSING_GRANULAR_LOCKS == 1 ) && ( configNUMBER_OF_CORES > 1 ) )
|
||||
portSPINLOCK_TYPE xTaskSpinlock;
|
||||
portSPINLOCK_TYPE xISRSpinlock;
|
||||
#endif /* #if ( ( portUSING_GRANULAR_LOCKS == 1 ) && ( configNUMBER_OF_CORES > 1 ) ) */
|
||||
} xQUEUE;
|
||||
|
||||
/* The old xQUEUE name is maintained above then typedefed to the new Queue_t
|
||||
|
@ -251,12 +256,27 @@ static void prvInitialiseNewQueue( const UBaseType_t uxQueueLength,
|
|||
#endif
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/*
|
||||
* Macros to mark the start and end of a critical code region.
|
||||
*/
|
||||
#if ( portUSING_GRANULAR_LOCKS == 1 )
|
||||
#define queueENTER_CRITICAL( pxQueue ) taskDATA_GROUP_ENTER_CRITICAL( &pxQueue->xTaskSpinlock, &pxQueue->xISRSpinlock )
|
||||
#define queueENTER_CRITICAL_FROM_ISR( pxQueue, puxSavedInterruptStatus ) taskDATA_GROUP_ENTER_CRITICAL_FROM_ISR( &pxQueue->xISRSpinlock, puxSavedInterruptStatus )
|
||||
#define queueEXIT_CRITICAL( pxQueue ) taskDATA_GROUP_EXIT_CRITICAL( &pxQueue->xTaskSpinlock, &pxQueue->xISRSpinlock )
|
||||
#define queueEXIT_CRITICAL_FROM_ISR( uxSavedInterruptStatus, pxQueue ) taskDATA_GROUP_EXIT_CRITICAL_FROM_ISR( uxSavedInterruptStatus, &pxQueue->xISRSpinlock )
|
||||
#else /* #if ( portUSING_GRANULAR_LOCKS == 1 ) */
|
||||
#define queueENTER_CRITICAL( pxQueue ) taskENTER_CRITICAL();
|
||||
#define queueENTER_CRITICAL_FROM_ISR( pxQueue, puxSavedInterruptStatus ) do { *( puxSavedInterruptStatus ) = taskENTER_CRITICAL_FROM_ISR(); } while( 0 )
|
||||
#define queueEXIT_CRITICAL( pxQueue ) taskEXIT_CRITICAL();
|
||||
#define queueEXIT_CRITICAL_FROM_ISR( uxSavedInterruptStatus, pxQueue ) taskEXIT_CRITICAL_FROM_ISR( uxSavedInterruptStatus );
|
||||
#endif /* #if ( portUSING_GRANULAR_LOCKS == 1 ) */
|
||||
|
||||
/*
|
||||
* Macro to mark a queue as locked. Locking a queue prevents an ISR from
|
||||
* accessing the queue event lists.
|
||||
*/
|
||||
#define prvLockQueue( pxQueue ) \
|
||||
taskENTER_CRITICAL(); \
|
||||
queueENTER_CRITICAL( pxQueue ); \
|
||||
{ \
|
||||
if( ( pxQueue )->cRxLock == queueUNLOCKED ) \
|
||||
{ \
|
||||
|
@ -267,7 +287,7 @@ static void prvInitialiseNewQueue( const UBaseType_t uxQueueLength,
|
|||
( pxQueue )->cTxLock = queueLOCKED_UNMODIFIED; \
|
||||
} \
|
||||
} \
|
||||
taskEXIT_CRITICAL()
|
||||
queueEXIT_CRITICAL( pxQueue )
|
||||
|
||||
/*
|
||||
* Macro to increment cTxLock member of the queue data structure. It is
|
||||
|
@ -298,6 +318,57 @@ static void prvInitialiseNewQueue( const UBaseType_t uxQueueLength,
|
|||
( pxQueue )->cRxLock = ( int8_t ) ( ( cRxLock ) + ( int8_t ) 1 ); \
|
||||
} \
|
||||
} while( 0 )
|
||||
|
||||
/*
|
||||
* Macro used to lock and unlock a queue. When a task locks a queue, the
|
||||
* task will have thread safe non-deterministic access to the queue.
|
||||
* - Concurrent access from other tasks will be blocked by the xTaskSpinlock
|
||||
* - Concurrent access from ISRs will be pended
|
||||
*
|
||||
* When the tasks unlocks the queue, all pended access attempts are handled.
|
||||
*/
|
||||
#if ( ( portUSING_GRANULAR_LOCKS == 1 ) && ( configNUMBER_OF_CORES > 1 ) )
|
||||
#define queueLOCK( pxQueue ) \
|
||||
do { \
|
||||
vTaskPreemptionDisable( NULL ); \
|
||||
prvLockQueue( ( pxQueue ) ); \
|
||||
portGET_SPINLOCK( portGET_CORE_ID(), &( pxQueue->xTaskSpinlock ) ); \
|
||||
} while( 0 )
|
||||
#define queueUNLOCK( pxQueue, xYieldAPI ) \
|
||||
do { \
|
||||
prvUnlockQueue( ( pxQueue ) ); \
|
||||
portRELEASE_SPINLOCK( portGET_CORE_ID(), &( pxQueue->xTaskSpinlock ) ); \
|
||||
vTaskPreemptionEnable( NULL ); \
|
||||
if( ( xYieldAPI ) == pdTRUE ) \
|
||||
{ \
|
||||
taskYIELD_WITHIN_API(); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
mtCOVERAGE_TEST_MARKER(); \
|
||||
} \
|
||||
} while( 0 )
|
||||
#else /* #if ( ( portUSING_GRANULAR_LOCKS == 1 ) && ( configNUMBER_OF_CORES > 1 ) ) */
|
||||
#define queueLOCK( pxQueue ) \
|
||||
do { \
|
||||
vTaskSuspendAll(); \
|
||||
prvLockQueue( ( pxQueue ) ); \
|
||||
} while( 0 )
|
||||
#define queueUNLOCK( pxQueue, xYieldAPI ) \
|
||||
do { \
|
||||
BaseType_t xAlreadyYielded; \
|
||||
prvUnlockQueue( ( pxQueue ) ); \
|
||||
xAlreadyYielded = xTaskResumeAll(); \
|
||||
if( ( xAlreadyYielded == pdFALSE ) && ( ( xYieldAPI ) == pdTRUE ) ) \
|
||||
{ \
|
||||
taskYIELD_WITHIN_API(); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
mtCOVERAGE_TEST_MARKER(); \
|
||||
} \
|
||||
} while( 0 )
|
||||
#endif /* #if ( ( portUSING_GRANULAR_LOCKS == 1 ) && ( configNUMBER_OF_CORES > 1 ) ) */
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
BaseType_t xQueueGenericReset( QueueHandle_t xQueue,
|
||||
|
@ -310,12 +381,22 @@ BaseType_t xQueueGenericReset( QueueHandle_t xQueue,
|
|||
|
||||
configASSERT( pxQueue );
|
||||
|
||||
#if ( ( portUSING_GRANULAR_LOCKS == 1 ) && ( configNUMBER_OF_CORES > 1 ) )
|
||||
{
|
||||
if( xNewQueue == pdTRUE )
|
||||
{
|
||||
portINIT_SPINLOCK( &( pxQueue->xTaskSpinlock ) );
|
||||
portINIT_SPINLOCK( &( pxQueue->xISRSpinlock ) );
|
||||
}
|
||||
}
|
||||
#endif /* #if ( ( portUSING_GRANULAR_LOCKS == 1 ) && ( configNUMBER_OF_CORES > 1 ) ) */
|
||||
|
||||
if( ( pxQueue != NULL ) &&
|
||||
( pxQueue->uxLength >= 1U ) &&
|
||||
/* Check for multiplication overflow. */
|
||||
( ( SIZE_MAX / pxQueue->uxLength ) >= pxQueue->uxItemSize ) )
|
||||
{
|
||||
taskENTER_CRITICAL();
|
||||
queueENTER_CRITICAL( pxQueue );
|
||||
{
|
||||
pxQueue->u.xQueue.pcTail = pxQueue->pcHead + ( pxQueue->uxLength * pxQueue->uxItemSize );
|
||||
pxQueue->uxMessagesWaiting = ( UBaseType_t ) 0U;
|
||||
|
@ -354,7 +435,7 @@ BaseType_t xQueueGenericReset( QueueHandle_t xQueue,
|
|||
vListInitialise( &( pxQueue->xTasksWaitingToReceive ) );
|
||||
}
|
||||
}
|
||||
taskEXIT_CRITICAL();
|
||||
queueEXIT_CRITICAL( pxQueue );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -703,7 +784,7 @@ static void prvInitialiseNewQueue( const UBaseType_t uxQueueLength,
|
|||
* calling task is the mutex holder, but not a good way of determining the
|
||||
* identity of the mutex holder, as the holder may change between the
|
||||
* following critical section exiting and the function returning. */
|
||||
taskENTER_CRITICAL();
|
||||
queueENTER_CRITICAL( pxSemaphore );
|
||||
{
|
||||
if( pxSemaphore->uxQueueType == queueQUEUE_IS_MUTEX )
|
||||
{
|
||||
|
@ -714,7 +795,7 @@ static void prvInitialiseNewQueue( const UBaseType_t uxQueueLength,
|
|||
pxReturn = NULL;
|
||||
}
|
||||
}
|
||||
taskEXIT_CRITICAL();
|
||||
queueEXIT_CRITICAL( pxSemaphore );
|
||||
|
||||
traceRETURN_xQueueGetMutexHolder( pxReturn );
|
||||
|
||||
|
@ -968,7 +1049,7 @@ BaseType_t xQueueGenericSend( QueueHandle_t xQueue,
|
|||
|
||||
for( ; ; )
|
||||
{
|
||||
taskENTER_CRITICAL();
|
||||
queueENTER_CRITICAL( pxQueue );
|
||||
{
|
||||
/* 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
|
||||
|
@ -1074,7 +1155,7 @@ BaseType_t xQueueGenericSend( QueueHandle_t xQueue,
|
|||
}
|
||||
#endif /* configUSE_QUEUE_SETS */
|
||||
|
||||
taskEXIT_CRITICAL();
|
||||
queueEXIT_CRITICAL( pxQueue );
|
||||
|
||||
traceRETURN_xQueueGenericSend( pdPASS );
|
||||
|
||||
|
@ -1086,7 +1167,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();
|
||||
queueEXIT_CRITICAL( pxQueue );
|
||||
|
||||
/* Return to the original privilege level before exiting
|
||||
* the function. */
|
||||
|
@ -1109,13 +1190,12 @@ BaseType_t xQueueGenericSend( QueueHandle_t xQueue,
|
|||
}
|
||||
}
|
||||
}
|
||||
taskEXIT_CRITICAL();
|
||||
queueEXIT_CRITICAL( pxQueue );
|
||||
|
||||
/* Interrupts and other tasks can send to and receive from the queue
|
||||
* now the critical section has been exited. */
|
||||
|
||||
vTaskSuspendAll();
|
||||
prvLockQueue( pxQueue );
|
||||
queueLOCK( pxQueue );
|
||||
|
||||
/* Update the timeout state to see if it has expired yet. */
|
||||
if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE )
|
||||
|
@ -1125,35 +1205,18 @@ BaseType_t xQueueGenericSend( QueueHandle_t xQueue,
|
|||
traceBLOCKING_ON_QUEUE_SEND( pxQueue );
|
||||
vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToSend ), xTicksToWait );
|
||||
|
||||
/* Unlocking the queue means queue events can effect the
|
||||
* event list. It is possible that interrupts occurring now
|
||||
* remove this task from the event list again - but as the
|
||||
* scheduler is suspended the task will go onto the pending
|
||||
* ready list instead of the actual ready list. */
|
||||
prvUnlockQueue( pxQueue );
|
||||
|
||||
/* Resuming the scheduler will move tasks from the pending
|
||||
* ready list into the ready list - so it is feasible that this
|
||||
* task is already in the ready list before it yields - in which
|
||||
* case the yield will not cause a context switch unless there
|
||||
* is also a higher priority task in the pending ready list. */
|
||||
if( xTaskResumeAll() == pdFALSE )
|
||||
{
|
||||
taskYIELD_WITHIN_API();
|
||||
}
|
||||
queueUNLOCK( pxQueue, pdTRUE );
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Try again. */
|
||||
prvUnlockQueue( pxQueue );
|
||||
( void ) xTaskResumeAll();
|
||||
queueUNLOCK( pxQueue, pdFALSE );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* The timeout has expired. */
|
||||
prvUnlockQueue( pxQueue );
|
||||
( void ) xTaskResumeAll();
|
||||
queueUNLOCK( pxQueue, pdFALSE );
|
||||
|
||||
traceQUEUE_SEND_FAILED( pxQueue );
|
||||
traceRETURN_xQueueGenericSend( errQUEUE_FULL );
|
||||
|
@ -1203,7 +1266,7 @@ BaseType_t xQueueGenericSendFromISR( QueueHandle_t xQueue,
|
|||
/* MISRA Ref 4.7.1 [Return value shall be checked] */
|
||||
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#dir-47 */
|
||||
/* coverity[misra_c_2012_directive_4_7_violation] */
|
||||
uxSavedInterruptStatus = ( UBaseType_t ) taskENTER_CRITICAL_FROM_ISR();
|
||||
queueENTER_CRITICAL_FROM_ISR( pxQueue, &uxSavedInterruptStatus );
|
||||
{
|
||||
if( ( pxQueue->uxMessagesWaiting < pxQueue->uxLength ) || ( xCopyPosition == queueOVERWRITE ) )
|
||||
{
|
||||
|
@ -1328,7 +1391,7 @@ BaseType_t xQueueGenericSendFromISR( QueueHandle_t xQueue,
|
|||
xReturn = errQUEUE_FULL;
|
||||
}
|
||||
}
|
||||
taskEXIT_CRITICAL_FROM_ISR( uxSavedInterruptStatus );
|
||||
queueEXIT_CRITICAL_FROM_ISR( uxSavedInterruptStatus, pxQueue );
|
||||
|
||||
traceRETURN_xQueueGenericSendFromISR( xReturn );
|
||||
|
||||
|
@ -1381,7 +1444,7 @@ BaseType_t xQueueGiveFromISR( QueueHandle_t xQueue,
|
|||
/* MISRA Ref 4.7.1 [Return value shall be checked] */
|
||||
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#dir-47 */
|
||||
/* coverity[misra_c_2012_directive_4_7_violation] */
|
||||
uxSavedInterruptStatus = ( UBaseType_t ) taskENTER_CRITICAL_FROM_ISR();
|
||||
queueENTER_CRITICAL_FROM_ISR( pxQueue, &uxSavedInterruptStatus );
|
||||
{
|
||||
const UBaseType_t uxMessagesWaiting = pxQueue->uxMessagesWaiting;
|
||||
|
||||
|
@ -1501,7 +1564,7 @@ BaseType_t xQueueGiveFromISR( QueueHandle_t xQueue,
|
|||
xReturn = errQUEUE_FULL;
|
||||
}
|
||||
}
|
||||
taskEXIT_CRITICAL_FROM_ISR( uxSavedInterruptStatus );
|
||||
queueEXIT_CRITICAL_FROM_ISR( uxSavedInterruptStatus, pxQueue );
|
||||
|
||||
traceRETURN_xQueueGiveFromISR( xReturn );
|
||||
|
||||
|
@ -1535,7 +1598,7 @@ BaseType_t xQueueReceive( QueueHandle_t xQueue,
|
|||
|
||||
for( ; ; )
|
||||
{
|
||||
taskENTER_CRITICAL();
|
||||
queueENTER_CRITICAL( pxQueue );
|
||||
{
|
||||
const UBaseType_t uxMessagesWaiting = pxQueue->uxMessagesWaiting;
|
||||
|
||||
|
@ -1567,7 +1630,7 @@ BaseType_t xQueueReceive( QueueHandle_t xQueue,
|
|||
mtCOVERAGE_TEST_MARKER();
|
||||
}
|
||||
|
||||
taskEXIT_CRITICAL();
|
||||
queueEXIT_CRITICAL( pxQueue );
|
||||
|
||||
traceRETURN_xQueueReceive( pdPASS );
|
||||
|
||||
|
@ -1579,7 +1642,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();
|
||||
queueEXIT_CRITICAL( pxQueue );
|
||||
|
||||
traceQUEUE_RECEIVE_FAILED( pxQueue );
|
||||
traceRETURN_xQueueReceive( errQUEUE_EMPTY );
|
||||
|
@ -1600,13 +1663,12 @@ BaseType_t xQueueReceive( QueueHandle_t xQueue,
|
|||
}
|
||||
}
|
||||
}
|
||||
taskEXIT_CRITICAL();
|
||||
queueEXIT_CRITICAL( pxQueue );
|
||||
|
||||
/* Interrupts and other tasks can send to and receive from the queue
|
||||
* now the critical section has been exited. */
|
||||
|
||||
vTaskSuspendAll();
|
||||
prvLockQueue( pxQueue );
|
||||
queueLOCK( pxQueue );
|
||||
|
||||
/* Update the timeout state to see if it has expired yet. */
|
||||
if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE )
|
||||
|
@ -1617,31 +1679,20 @@ BaseType_t xQueueReceive( QueueHandle_t xQueue,
|
|||
{
|
||||
traceBLOCKING_ON_QUEUE_RECEIVE( pxQueue );
|
||||
vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToReceive ), xTicksToWait );
|
||||
prvUnlockQueue( pxQueue );
|
||||
|
||||
if( xTaskResumeAll() == pdFALSE )
|
||||
{
|
||||
taskYIELD_WITHIN_API();
|
||||
}
|
||||
else
|
||||
{
|
||||
mtCOVERAGE_TEST_MARKER();
|
||||
}
|
||||
queueUNLOCK( pxQueue, pdTRUE );
|
||||
}
|
||||
else
|
||||
{
|
||||
/* The queue contains data again. Loop back to try and read the
|
||||
* data. */
|
||||
prvUnlockQueue( pxQueue );
|
||||
( void ) xTaskResumeAll();
|
||||
queueUNLOCK( pxQueue, pdFALSE );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Timed out. If there is no data in the queue exit, otherwise loop
|
||||
* back and attempt to read the data. */
|
||||
prvUnlockQueue( pxQueue );
|
||||
( void ) xTaskResumeAll();
|
||||
queueUNLOCK( pxQueue, pdFALSE );
|
||||
|
||||
if( prvIsQueueEmpty( pxQueue ) != pdFALSE )
|
||||
{
|
||||
|
@ -1688,7 +1739,7 @@ BaseType_t xQueueSemaphoreTake( QueueHandle_t xQueue,
|
|||
|
||||
for( ; ; )
|
||||
{
|
||||
taskENTER_CRITICAL();
|
||||
queueENTER_CRITICAL( pxQueue );
|
||||
{
|
||||
/* Semaphores are queues with an item size of 0, and where the
|
||||
* number of messages in the queue is the semaphore's count value. */
|
||||
|
@ -1737,7 +1788,7 @@ BaseType_t xQueueSemaphoreTake( QueueHandle_t xQueue,
|
|||
mtCOVERAGE_TEST_MARKER();
|
||||
}
|
||||
|
||||
taskEXIT_CRITICAL();
|
||||
queueEXIT_CRITICAL( pxQueue );
|
||||
|
||||
traceRETURN_xQueueSemaphoreTake( pdPASS );
|
||||
|
||||
|
@ -1749,7 +1800,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();
|
||||
queueEXIT_CRITICAL( pxQueue );
|
||||
|
||||
traceQUEUE_RECEIVE_FAILED( pxQueue );
|
||||
traceRETURN_xQueueSemaphoreTake( errQUEUE_EMPTY );
|
||||
|
@ -1770,13 +1821,12 @@ BaseType_t xQueueSemaphoreTake( QueueHandle_t xQueue,
|
|||
}
|
||||
}
|
||||
}
|
||||
taskEXIT_CRITICAL();
|
||||
queueEXIT_CRITICAL( pxQueue );
|
||||
|
||||
/* Interrupts and other tasks can give to and take from the semaphore
|
||||
* now the critical section has been exited. */
|
||||
|
||||
vTaskSuspendAll();
|
||||
prvLockQueue( pxQueue );
|
||||
queueLOCK( pxQueue );
|
||||
|
||||
/* Update the timeout state to see if it has expired yet. */
|
||||
if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE )
|
||||
|
@ -1803,30 +1853,19 @@ BaseType_t xQueueSemaphoreTake( QueueHandle_t xQueue,
|
|||
#endif /* if ( configUSE_MUTEXES == 1 ) */
|
||||
|
||||
vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToReceive ), xTicksToWait );
|
||||
prvUnlockQueue( pxQueue );
|
||||
|
||||
if( xTaskResumeAll() == pdFALSE )
|
||||
{
|
||||
taskYIELD_WITHIN_API();
|
||||
}
|
||||
else
|
||||
{
|
||||
mtCOVERAGE_TEST_MARKER();
|
||||
}
|
||||
queueUNLOCK( pxQueue, pdTRUE );
|
||||
}
|
||||
else
|
||||
{
|
||||
/* There was no timeout and the semaphore count was not 0, so
|
||||
* attempt to take the semaphore again. */
|
||||
prvUnlockQueue( pxQueue );
|
||||
( void ) xTaskResumeAll();
|
||||
queueUNLOCK( pxQueue, pdFALSE );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Timed out. */
|
||||
prvUnlockQueue( pxQueue );
|
||||
( void ) xTaskResumeAll();
|
||||
queueUNLOCK( pxQueue, pdFALSE );
|
||||
|
||||
/* If the semaphore count is 0 exit now as the timeout has
|
||||
* expired. Otherwise return to attempt to take the semaphore that is
|
||||
|
@ -1841,7 +1880,7 @@ BaseType_t xQueueSemaphoreTake( QueueHandle_t xQueue,
|
|||
* test the mutex type again to check it is actually a mutex. */
|
||||
if( xInheritanceOccurred != pdFALSE )
|
||||
{
|
||||
taskENTER_CRITICAL();
|
||||
queueENTER_CRITICAL( pxQueue );
|
||||
{
|
||||
UBaseType_t uxHighestWaitingPriority;
|
||||
|
||||
|
@ -1861,7 +1900,7 @@ BaseType_t xQueueSemaphoreTake( QueueHandle_t xQueue,
|
|||
/* coverity[overrun] */
|
||||
vTaskPriorityDisinheritAfterTimeout( pxQueue->u.xSemaphore.xMutexHolder, uxHighestWaitingPriority );
|
||||
}
|
||||
taskEXIT_CRITICAL();
|
||||
queueEXIT_CRITICAL( pxQueue );
|
||||
}
|
||||
}
|
||||
#endif /* configUSE_MUTEXES */
|
||||
|
@ -1907,7 +1946,7 @@ BaseType_t xQueuePeek( QueueHandle_t xQueue,
|
|||
|
||||
for( ; ; )
|
||||
{
|
||||
taskENTER_CRITICAL();
|
||||
queueENTER_CRITICAL( pxQueue );
|
||||
{
|
||||
const UBaseType_t uxMessagesWaiting = pxQueue->uxMessagesWaiting;
|
||||
|
||||
|
@ -1945,7 +1984,7 @@ BaseType_t xQueuePeek( QueueHandle_t xQueue,
|
|||
mtCOVERAGE_TEST_MARKER();
|
||||
}
|
||||
|
||||
taskEXIT_CRITICAL();
|
||||
queueEXIT_CRITICAL( pxQueue );
|
||||
|
||||
traceRETURN_xQueuePeek( pdPASS );
|
||||
|
||||
|
@ -1957,7 +1996,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();
|
||||
queueEXIT_CRITICAL( pxQueue );
|
||||
|
||||
traceQUEUE_PEEK_FAILED( pxQueue );
|
||||
traceRETURN_xQueuePeek( errQUEUE_EMPTY );
|
||||
|
@ -1979,13 +2018,12 @@ BaseType_t xQueuePeek( QueueHandle_t xQueue,
|
|||
}
|
||||
}
|
||||
}
|
||||
taskEXIT_CRITICAL();
|
||||
queueEXIT_CRITICAL( pxQueue );
|
||||
|
||||
/* Interrupts and other tasks can send to and receive from the queue
|
||||
* now that the critical section has been exited. */
|
||||
|
||||
vTaskSuspendAll();
|
||||
prvLockQueue( pxQueue );
|
||||
queueLOCK( pxQueue );
|
||||
|
||||
/* Update the timeout state to see if it has expired yet. */
|
||||
if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE )
|
||||
|
@ -1996,31 +2034,20 @@ BaseType_t xQueuePeek( QueueHandle_t xQueue,
|
|||
{
|
||||
traceBLOCKING_ON_QUEUE_PEEK( pxQueue );
|
||||
vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToReceive ), xTicksToWait );
|
||||
prvUnlockQueue( pxQueue );
|
||||
|
||||
if( xTaskResumeAll() == pdFALSE )
|
||||
{
|
||||
taskYIELD_WITHIN_API();
|
||||
}
|
||||
else
|
||||
{
|
||||
mtCOVERAGE_TEST_MARKER();
|
||||
}
|
||||
queueUNLOCK( pxQueue, pdTRUE );
|
||||
}
|
||||
else
|
||||
{
|
||||
/* There is data in the queue now, so don't enter the blocked
|
||||
* state, instead return to try and obtain the data. */
|
||||
prvUnlockQueue( pxQueue );
|
||||
( void ) xTaskResumeAll();
|
||||
queueUNLOCK( pxQueue, pdFALSE );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* The timeout has expired. If there is still no data in the queue
|
||||
* exit, otherwise go back and try to read the data again. */
|
||||
prvUnlockQueue( pxQueue );
|
||||
( void ) xTaskResumeAll();
|
||||
queueUNLOCK( pxQueue, pdFALSE );
|
||||
|
||||
if( prvIsQueueEmpty( pxQueue ) != pdFALSE )
|
||||
{
|
||||
|
@ -2070,7 +2097,7 @@ BaseType_t xQueueReceiveFromISR( QueueHandle_t xQueue,
|
|||
/* MISRA Ref 4.7.1 [Return value shall be checked] */
|
||||
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#dir-47 */
|
||||
/* coverity[misra_c_2012_directive_4_7_violation] */
|
||||
uxSavedInterruptStatus = ( UBaseType_t ) taskENTER_CRITICAL_FROM_ISR();
|
||||
queueENTER_CRITICAL_FROM_ISR( pxQueue, &uxSavedInterruptStatus );
|
||||
{
|
||||
const UBaseType_t uxMessagesWaiting = pxQueue->uxMessagesWaiting;
|
||||
|
||||
|
@ -2130,7 +2157,7 @@ BaseType_t xQueueReceiveFromISR( QueueHandle_t xQueue,
|
|||
traceQUEUE_RECEIVE_FROM_ISR_FAILED( pxQueue );
|
||||
}
|
||||
}
|
||||
taskEXIT_CRITICAL_FROM_ISR( uxSavedInterruptStatus );
|
||||
queueEXIT_CRITICAL_FROM_ISR( uxSavedInterruptStatus, pxQueue );
|
||||
|
||||
traceRETURN_xQueueReceiveFromISR( xReturn );
|
||||
|
||||
|
@ -2171,7 +2198,7 @@ BaseType_t xQueuePeekFromISR( QueueHandle_t xQueue,
|
|||
/* MISRA Ref 4.7.1 [Return value shall be checked] */
|
||||
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#dir-47 */
|
||||
/* coverity[misra_c_2012_directive_4_7_violation] */
|
||||
uxSavedInterruptStatus = ( UBaseType_t ) taskENTER_CRITICAL_FROM_ISR();
|
||||
queueENTER_CRITICAL_FROM_ISR( pxQueue, &uxSavedInterruptStatus );
|
||||
{
|
||||
/* Cannot block in an ISR, so check there is data available. */
|
||||
if( pxQueue->uxMessagesWaiting > ( UBaseType_t ) 0 )
|
||||
|
@ -2192,7 +2219,7 @@ BaseType_t xQueuePeekFromISR( QueueHandle_t xQueue,
|
|||
traceQUEUE_PEEK_FROM_ISR_FAILED( pxQueue );
|
||||
}
|
||||
}
|
||||
taskEXIT_CRITICAL_FROM_ISR( uxSavedInterruptStatus );
|
||||
queueEXIT_CRITICAL_FROM_ISR( uxSavedInterruptStatus, pxQueue );
|
||||
|
||||
traceRETURN_xQueuePeekFromISR( xReturn );
|
||||
|
||||
|
@ -2208,11 +2235,11 @@ UBaseType_t uxQueueMessagesWaiting( const QueueHandle_t xQueue )
|
|||
|
||||
configASSERT( xQueue );
|
||||
|
||||
portBASE_TYPE_ENTER_CRITICAL();
|
||||
queueENTER_CRITICAL( xQueue );
|
||||
{
|
||||
uxReturn = ( ( Queue_t * ) xQueue )->uxMessagesWaiting;
|
||||
}
|
||||
portBASE_TYPE_EXIT_CRITICAL();
|
||||
queueEXIT_CRITICAL( xQueue );
|
||||
|
||||
traceRETURN_uxQueueMessagesWaiting( uxReturn );
|
||||
|
||||
|
@ -2229,11 +2256,11 @@ UBaseType_t uxQueueSpacesAvailable( const QueueHandle_t xQueue )
|
|||
|
||||
configASSERT( pxQueue );
|
||||
|
||||
portBASE_TYPE_ENTER_CRITICAL();
|
||||
queueENTER_CRITICAL( pxQueue );
|
||||
{
|
||||
uxReturn = ( UBaseType_t ) ( pxQueue->uxLength - pxQueue->uxMessagesWaiting );
|
||||
}
|
||||
portBASE_TYPE_EXIT_CRITICAL();
|
||||
queueEXIT_CRITICAL( pxQueue );
|
||||
|
||||
traceRETURN_uxQueueSpacesAvailable( uxReturn );
|
||||
|
||||
|
@ -2499,13 +2526,14 @@ static void prvCopyDataFromQueue( Queue_t * const pxQueue,
|
|||
|
||||
static void prvUnlockQueue( Queue_t * const pxQueue )
|
||||
{
|
||||
/* THIS FUNCTION MUST BE CALLED WITH THE SCHEDULER SUSPENDED. */
|
||||
/* THIS FUNCTION MUST BE CALLED WITH THE SCHEDULER SUSPENDED WHEN portUSING_GRANULAR_LOCKS IS 0.
|
||||
* IT MUST BE CALLED WITH TASK PREEMTION DISABLED WHEN portUSING_GRANULAR_LOCKS IS 1. */
|
||||
|
||||
/* The lock counts contains the number of extra data items placed or
|
||||
* 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();
|
||||
queueENTER_CRITICAL( pxQueue );
|
||||
{
|
||||
int8_t cTxLock = pxQueue->cTxLock;
|
||||
|
||||
|
@ -2583,10 +2611,10 @@ static void prvUnlockQueue( Queue_t * const pxQueue )
|
|||
|
||||
pxQueue->cTxLock = queueUNLOCKED;
|
||||
}
|
||||
taskEXIT_CRITICAL();
|
||||
queueEXIT_CRITICAL( pxQueue );
|
||||
|
||||
/* Do the same for the Rx lock. */
|
||||
taskENTER_CRITICAL();
|
||||
queueENTER_CRITICAL( pxQueue );
|
||||
{
|
||||
int8_t cRxLock = pxQueue->cRxLock;
|
||||
|
||||
|
@ -2613,7 +2641,7 @@ static void prvUnlockQueue( Queue_t * const pxQueue )
|
|||
|
||||
pxQueue->cRxLock = queueUNLOCKED;
|
||||
}
|
||||
taskEXIT_CRITICAL();
|
||||
queueEXIT_CRITICAL( pxQueue );
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
|
@ -2621,7 +2649,7 @@ static BaseType_t prvIsQueueEmpty( const Queue_t * pxQueue )
|
|||
{
|
||||
BaseType_t xReturn;
|
||||
|
||||
taskENTER_CRITICAL();
|
||||
queueENTER_CRITICAL( pxQueue );
|
||||
{
|
||||
if( pxQueue->uxMessagesWaiting == ( UBaseType_t ) 0 )
|
||||
{
|
||||
|
@ -2632,7 +2660,7 @@ static BaseType_t prvIsQueueEmpty( const Queue_t * pxQueue )
|
|||
xReturn = pdFALSE;
|
||||
}
|
||||
}
|
||||
taskEXIT_CRITICAL();
|
||||
queueEXIT_CRITICAL( pxQueue );
|
||||
|
||||
return xReturn;
|
||||
}
|
||||
|
@ -2666,7 +2694,7 @@ static BaseType_t prvIsQueueFull( const Queue_t * pxQueue )
|
|||
{
|
||||
BaseType_t xReturn;
|
||||
|
||||
taskENTER_CRITICAL();
|
||||
queueENTER_CRITICAL( pxQueue );
|
||||
{
|
||||
if( pxQueue->uxMessagesWaiting == pxQueue->uxLength )
|
||||
{
|
||||
|
@ -2677,7 +2705,7 @@ static BaseType_t prvIsQueueFull( const Queue_t * pxQueue )
|
|||
xReturn = pdFALSE;
|
||||
}
|
||||
}
|
||||
taskEXIT_CRITICAL();
|
||||
queueEXIT_CRITICAL( pxQueue );
|
||||
|
||||
return xReturn;
|
||||
}
|
||||
|
@ -3157,7 +3185,7 @@ BaseType_t xQueueIsQueueFullFromISR( const QueueHandle_t xQueue )
|
|||
* time a yield will be performed. If an item is added to the queue while
|
||||
* the queue is locked, and the calling task blocks on the queue, then the
|
||||
* calling task will be immediately unblocked when the queue is unlocked. */
|
||||
prvLockQueue( pxQueue );
|
||||
queueLOCK( pxQueue );
|
||||
|
||||
if( pxQueue->uxMessagesWaiting == ( UBaseType_t ) 0U )
|
||||
{
|
||||
|
@ -3169,7 +3197,7 @@ BaseType_t xQueueIsQueueFullFromISR( const QueueHandle_t xQueue )
|
|||
mtCOVERAGE_TEST_MARKER();
|
||||
}
|
||||
|
||||
prvUnlockQueue( pxQueue );
|
||||
queueUNLOCK( pxQueue, pdFALSE );
|
||||
|
||||
traceRETURN_vQueueWaitForMessageRestricted();
|
||||
}
|
||||
|
@ -3221,17 +3249,18 @@ BaseType_t xQueueIsQueueFullFromISR( const QueueHandle_t xQueue )
|
|||
QueueSetHandle_t xQueueSet )
|
||||
{
|
||||
BaseType_t xReturn;
|
||||
Queue_t * const pxQueue = xQueueOrSemaphore;
|
||||
|
||||
traceENTER_xQueueAddToSet( xQueueOrSemaphore, xQueueSet );
|
||||
|
||||
taskENTER_CRITICAL();
|
||||
queueENTER_CRITICAL( pxQueue );
|
||||
{
|
||||
if( ( ( Queue_t * ) xQueueOrSemaphore )->pxQueueSetContainer != NULL )
|
||||
if( pxQueue->pxQueueSetContainer != NULL )
|
||||
{
|
||||
/* Cannot add a queue/semaphore to more than one queue set. */
|
||||
xReturn = pdFAIL;
|
||||
}
|
||||
else if( ( ( Queue_t * ) xQueueOrSemaphore )->uxMessagesWaiting != ( UBaseType_t ) 0 )
|
||||
else if( pxQueue->uxMessagesWaiting != ( UBaseType_t ) 0 )
|
||||
{
|
||||
/* Cannot add a queue/semaphore to a queue set if there are already
|
||||
* items in the queue/semaphore. */
|
||||
|
@ -3239,11 +3268,11 @@ BaseType_t xQueueIsQueueFullFromISR( const QueueHandle_t xQueue )
|
|||
}
|
||||
else
|
||||
{
|
||||
( ( Queue_t * ) xQueueOrSemaphore )->pxQueueSetContainer = xQueueSet;
|
||||
pxQueue->pxQueueSetContainer = xQueueSet;
|
||||
xReturn = pdPASS;
|
||||
}
|
||||
}
|
||||
taskEXIT_CRITICAL();
|
||||
queueEXIT_CRITICAL( pxQueue );
|
||||
|
||||
traceRETURN_xQueueAddToSet( xReturn );
|
||||
|
||||
|
@ -3277,12 +3306,12 @@ BaseType_t xQueueIsQueueFullFromISR( const QueueHandle_t xQueue )
|
|||
}
|
||||
else
|
||||
{
|
||||
taskENTER_CRITICAL();
|
||||
queueENTER_CRITICAL( pxQueueOrSemaphore );
|
||||
{
|
||||
/* The queue is no longer contained in the set. */
|
||||
pxQueueOrSemaphore->pxQueueSetContainer = NULL;
|
||||
}
|
||||
taskEXIT_CRITICAL();
|
||||
queueEXIT_CRITICAL( pxQueueOrSemaphore );
|
||||
xReturn = pdPASS;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue