Quality RTOS & Embedded Software

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




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) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

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

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

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

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists