When I trying to clarify the pointers movement in queue operations, I found that I fell in confusion.
Below is my current understanding about queue operation, please point out my mis-undestanding points.
- First call xQueueGenericCreate() API to create a new Queue, the API will set pcHead pointer and then call xQueueGenericReset() to set the pcTail, pcReadFrom and pcWriteTo pointers, etc.
- After step 1), there will be pcHead == pcWriteTo, pcReadFrom + uxItemSize == pcTail;
- Then, I call xQueueGenericSend() to send one item to the BACK of the queue, it will call prvCopyDataToQueue() API. In prvCopyDataToQueue(), the pointer pcWriteTo is incremented.
- Finally, I want to read the stored item using API xQueueGenericReceive(). In this API, it will call prvCopyDataFromQueue() to retrieve the stored item. But it only increments pointer pcReadFrom and read its pointed data to buffer.
My questions are below:
(1) Which position is the Back of the Queue? Is it pointed by pcTail?
(2) Since when sending items to the Back of the Queue, it only changes pointer pcWriteTo; However, when I want to receive the stored items, it changes pointer pcReadFrom, but seems the pcReadFrom never changes after calling xQueueGenericReset() and maybe far from the position of the stored item.
I think my understanding is wrong, but I still cannot figure out the root cause. I’m reading the code of V8.2.1;
Hope someone can help me about the confusion, thanks in advance!