xQueuePeek() ?

Hello everyone. I am finding myself in need of a function to "peek" at the items in the queue (not restricted to only the first item), but without removing these items. I am trying to implement such a function. To save myself some work, I am wondering if such a function has already been made by someone. Also, I am wondering about which short-cuts I can take in the implementation. Peeking the queue will never block or unblock a task, and it will not change the queue itself. Thanks in advance for any information. Kind regards, Thiadmer Riemersma

xQueuePeek() ?

The queue storage area is simply an array packed with sequential data items.  If all you are doing is looking at what is in the queue then you can simply inspect pxQueue->pcReadFrom, then increment to the next item, wrapping where necessary.  As you are not removing anything or effecting any task states then it should be simple. Something like: QueuePeak(aQueue) { void *Next     Next = aQueue->pcReadFrom;     // Move to the next itme.     Next += pxQueue->uxItemSize;     // Wrap if necessary.     if( pxQueue->pcReadFrom >= pxQueue->pcTail ) {         Next = pxQueue->pcHead;     }     // Next now points to the first item that would be     // removed from the queue.     // If you want the next item after then then     // simply jump over the item again, checking     // for a wrap.     Next += pxQueue->uxItemSize;     if( pxQueue->pcReadFrom >= pxQueue->pcTail ) {         Next = pxQueue->pcHead;     }     // Next now points to the second item that would     // be removed from the queue.  As we are using     // the local variable Next, the queue itself is     // unchanged. } Of coarse you need to check how many items are actually in the queue, and take care of mutual exclusion to ensure an interrupt does not alter the queue as you are accessing it.

xQueuePeek() ?

Thanks. This is basically what I implemented myself. I was hoping to also be able to leave the queue unlocked, but in the general case, this is dangerous. Thiadmer