FreeRTOS Support Archive
The FreeRTOS support forum is used to obtain active support directly from Real
Time Engineers Ltd. In return for using our top quality software and services for
free, we request you play fair and do your bit to help others too! Sign up
to receive notifications of new support topics then help where you can.
This is a read only archive of threads posted to the FreeRTOS support forum.
The archive is updated every week, so will not always contain the very latest posts.
Use these archive pages to search previous posts. Use the Live FreeRTOS Forum
link to reply to a post, or start a new support thread.
[FreeRTOS Home] [Live FreeRTOS Forum] [FAQ] [Archive Top] [September 2005 Threads] queue flushPosted 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 flushPosted 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 flushPosted 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
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|