Skip to content

Commit a22b438

Browse files
authored
Overwrite existing QueueRegistry entries when a handle is added multiple times. (#306)
Overwrite an existing entry for a given xQueue handle when vQueueAddToRegistry is called with an xQueue handle of a queue that is already in the QueueRegistry.
1 parent a31018d commit a22b438

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

include/queue.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1491,6 +1491,10 @@ BaseType_t xQueueGiveMutexRecursive( QueueHandle_t xMutex ) PRIVILEGED_FUNCTION;
14911491
* does not effect the number of queues, semaphores and mutexes that can be
14921492
* created - just the number that the registry can hold.
14931493
*
1494+
* If vQueueAddToRegistry is called more than once with the same xQueue
1495+
* parameter, the registry will store the pcQueueName parameter from the
1496+
* most recent call to vQueueAddToRegistry.
1497+
*
14941498
* @param xQueue The handle of the queue being added to the registry. This
14951499
* is the handle returned by a call to xQueueCreate(). Semaphore and mutex
14961500
* handles can also be passed in here.

queue.c

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2730,24 +2730,37 @@ BaseType_t xQueueIsQueueFullFromISR( const QueueHandle_t xQueue )
27302730
configASSERT( xQueue );
27312731
configASSERT( pcQueueName );
27322732

2733+
QueueRegistryItem_t * pxEntryToWrite = NULL;
2734+
27332735
/* See if there is an empty space in the registry. A NULL name denotes
27342736
* a free slot. */
27352737
for( ux = ( UBaseType_t ) 0U; ux < ( UBaseType_t ) configQUEUE_REGISTRY_SIZE; ux++ )
27362738
{
2737-
if( xQueueRegistry[ ux ].pcQueueName == NULL )
2739+
/* Replace an existing entry if the queue is already in the registry. */
2740+
if( xQueueRegistry[ ux ].xHandle == xQueue )
27382741
{
2739-
/* Store the information on this queue. */
2740-
xQueueRegistry[ ux ].pcQueueName = pcQueueName;
2741-
xQueueRegistry[ ux ].xHandle = xQueue;
2742-
2743-
traceQUEUE_REGISTRY_ADD( xQueue, pcQueueName );
2742+
pxEntryToWrite = &( xQueueRegistry[ ux ] );
27442743
break;
27452744
}
2745+
/* Otherwise, store in the next empty location */
2746+
else if( ( NULL == pxEntryToWrite ) && ( xQueueRegistry[ ux ].pcQueueName == NULL ) )
2747+
{
2748+
pxEntryToWrite = &( xQueueRegistry[ ux ] );
2749+
}
27462750
else
27472751
{
27482752
mtCOVERAGE_TEST_MARKER();
27492753
}
27502754
}
2755+
2756+
if( NULL != pxEntryToWrite )
2757+
{
2758+
/* Store the information on this queue. */
2759+
pxEntryToWrite->pcQueueName = pcQueueName;
2760+
pxEntryToWrite->xHandle = xQueue;
2761+
2762+
traceQUEUE_REGISTRY_ADD( xQueue, pcQueueName );
2763+
}
27512764
}
27522765

27532766
#endif /* configQUEUE_REGISTRY_SIZE */

0 commit comments

Comments
 (0)