Quality RTOS & Embedded Software

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


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 ]    [ Privacy ]    [ Sitemap ]    [ ]


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

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


Careers

FreeRTOS and other embedded software careers at AWS.



FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Renesas

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

Xilinx Microblaze and Zynq partner