Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT




Loading

queue flush

Posted by Nobody/Anonymous on September 5, 2005
Hello.

Is there any smart way to implement a xQueueFlush to empty a queue other than

Enter critical
while(not empty)
get queue item and delete
exit critical

BR. Lars

RE: queue flush

Posted by Richard on September 8, 2005
Sorry for the delay in responding – but I have been out of the office for the last 4 days.

Items are queued by copy. They are copied into the buffer allocated to the queue when the queue is created. It is not strictly necessary therefore to delete the queued item, unless your application implementation (rather than the scheduler implementation) dictates this. For example, if the queued item is a pointer that points to dynamically allocated memory, and losing the queued item would mean there was no way of referring to the memory in order to free it again.

A queue can be emptied by simply resetting its structure members back to their starting condition, and in so going indicating that the queue is empty. I think the following code should achieve this, but have not tested this:

------
pxQueue->uxMessagesWaiting = 0;
pxQueue->pcWriteTo = pxQueue->pcHead;
pxQueue->pcReadFrom = pxQueue->pcHead + ( ( uxQueueLength - 1 ) * uxItemSize );
pxQueue->xRxLock = queueUNLOCKED;
pxQueue->xTxLock = queueUNLOCKED;

vListInitialise( &( pxQueue->xTasksWaitingToSend ) );
vListInitialise( &( pxQueue->xTasksWaitingToReceive ) );
------

Look at the function xQueueCreate() in queue.c for uxQueueLength and uxItemSize definitions.

You would also have to ensure that no tasks were blocked waiting on queue events (items to be posted onto the queue, or space to become available on the queue).


Regards.

RE: queue flush

Posted by juan schiavoni on November 24, 2008
Hi,

Also I need to flush a queue, and I need to know if this implementation of locks is fine:

taskENTER_CRITICAL();
{

pxQueue->uxMessagesWaiting = 0;
pxQueue->pcWriteTo = pxQueue->pcHead;
pxQueue->pcReadFrom = pxQueue->pcHead + ( ( pxQueue->uxLength = uxQueueLength - 1 ) * pxQueue->uxItemSize );

pxQueue->xRxLock = queueUNLOCKED;
pxQueue->xTxLock = queueUNLOCKED;

vListInitialise( &( pxQueue->xTasksWaitingToSend ) );
vListInitialise( &( pxQueue->xTasksWaitingToReceive ) );

}taskEXIT_CRITICAL();

Regards
Juan


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS