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] [June 2010 Threads] Code Provided for a vQueueFlush functionPosted by D-Kure on June 18, 2010 Hello All, I recently needed a queue flush function, and it seemed like a waste to use a while(xQueueReceive()) loop to flush the queue. Instead I came up with the following function void vQueueFlush( const xQueueHandle pxQueue ) { portBASE_TYPE xYield = pdFALSE;
taskENTER_CRITICAL();
/* Reset the queue to default state */ pxQueue->uxMessagesWaiting = 0; pxQueue->pcWriteTo = pxQueue->pcHead; pxQueue->pcReadFrom = pxQueue->pcHead + ( ( pxQueue->uxLength - 1 ) * pxQueue->uxItemSize );
/* Clear the event list waiting to send */ while (listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE ) { if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) == pdTRUE ) { /* The task waiting has a higher priority than this task. */ xYield = pdTRUE; } }
if (xYield == pdTRUE) { portYIELD_WITHIN_API(); }
taskEXIT_CRITICAL();
return; }
Now I have spotted some simlilar code by Richard Barry which also mentioned rxLocks and txLocks. I have not touched these as I am not sure what they do exactly. I have tested the code, and it works. It also saves real time when trying to use large queues. I created a queue of 5000 elements and when using this queue free function it saved 16ms of execution on an STM32 @ 72MHz. It would be great if this could be included in the next version of FreeRTOS. Regards Paul
RE: Code Provided for a vQueueFlush functionPosted by Dave on June 18, 2010 Can you post a link to this message in the feature request tracker?
I presume for a complete implementation you would also need to clear the tasks waiting to receive.
RE: Code Provided for a vQueueFlush functionPosted by D-Kure on June 18, 2010 As this is a flushing of the queue, I think that tasks that are waiting to receive still need to be blocked, waiting on data.
Its meant to flush the queue of all data, not necessarily reset the queue back to the default state.
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|