I must check if wueue is empty, becasue i have to turn off hardware, but i must be sure that all is received by this hardware. Now i can only do queuepick to check if it has something or not, but it does receive. I want only check if it is empty or not to wait for queue is empty if i want to turn off hardware.
P.S. it is thermal printer, in other tasks i send into queue some data, another task just sends it to printer, but printing takes time to empty queue. In some place i want to turn off printer power but i have to be sure that all data from queue is received by printer.
Is there simple macro e.g. IsQueueEmpty() without doing unnecesasary receive like in QueuePick?
Thanx richard_damon,
yes I know it, i even found in queue.h:
xQueueIsQueueEmptyFromISR
but version without ‘FromISR’ is only in queue.c file
No one of above functions are not in API and it is why i am asking. I want to know for sure that i can use function and in next freertos version it will be, becasue if it is not in API then name of that function may change.
In queue.c there is function to chack if queue is empty outside ISR and From ISR. If it would be in API then i would be very happy…
You can also call xQueuePeek() with a block time of zero. It will not remove any items from the queue. You might also consider calling xQueueReceive() with a block time of zero, if there is something in the queue I presume you want to process it, and if there isn’t it xQueueReceive() will return pdFALSE.
Hi Richard!
I dont want to process this queue. I want only to know if it is empty already. I can do xQueuePick but it is a waste of time to do receiving if i dont want to know results. Of course i have to prepare receiving buffer for pick… next wasting of time…
I thought that there is something that i can use to check if queue is empty.
I think however the best choice is to use uxQueueMessagesWaiting (in queue.h) All these functions use the same uxMessagesWaiting
it is used by prvIsQueueEmpty and xQueueIsQueueEmptyFromISR and uxQueueMessagesWaiting and uxQueueMessagesWaitingFromISR and maybe one or two more.
Hmmm, last question:
can i use
‘uxQueueMessagesWaiting’
and
‘uxQueueMessagesWaitingFromISR’
without worring that it dissapear in future releases of FreeRTOS? Or maybe you plan to add that functions to API on the website? That would be great to have it documented
‘uxQueueMessagesWaiting’
and
‘uxQueueMessagesWaitingFromISR’
without worring that it dissapear in future releases of FreeRTOS? Or maybe you plan to add that functions to API on the website? That would be great to have it documented
uxQueueMessagesWaiting is already documented in the API reference available on the website.
does the same? I mean, why my app hangs when i use that loop without entering critical region and without dissabling interrupts? It just checks variable, nothing more, and it that case it doesnt matter that i am calling uxQueueMessagesWaitingFromISR not from ISR, i checked that that variable ‘uxMessagesWaiting’ in queue struct is ‘volatile’ then it should work, i think.
definition of queue struct is in the queue.c file then the only way of checking only that volatile variable is to use
uxQueueMessagesWaitingFromISR(), but, in this case, why i have to use vTaskDelay(1) in ‘while’ loop since i dont disable interrupts??? i dont know….
uxQueMessagesWaiting has a short critical section as it needs to access two pointers, and wants to make sure that nobody can add or remove messages while it is performing its calculation. The returned result may not be how many messages are still in the queue, but will be a count of how many messages were in the queue at one point during the operation of the function.
As to using while loops to poll for the message. that is just bad practice. The issue is that while you are looping on this test, no lower priority tasks will get to run. If a lower priority task needs to run to put something into the queue, it will never happen.
If you want to wait for data, use a QueueGet, or a QueuePeek if you don’t want to remove the data. Then the task will be suspended until the queue has data and automatically resumed.