peek() method for BlockingReaderWriterCircularBuffer?
f18m opened this issue · comments
Hi,
I'm trying to replace the ReaderWriterQueue with BlockingReaderWriterCircularBuffer (my idea is that with the latter I can remove some arbitrary sleep() calls in producer/consumer threads).
However I noticed that there is no such thing like ReaderWriterQueue::peek() defined in BlockingReaderWriterCircularBuffer. Is it possible to add such API or is there a good reason why it's missing?
Thanks!
I think it could be implemented. Depends whether items->availableApprox()
being non zero guarantees an item is there, which I believe is the case.
Yeah, it would work because the consumer thread necessarily sees its own decrements on that semaphore, so if it sees the semaphore at non-zero, there must still actually be an element.
Added. Feel free to reopen if you find an issue with it.
that was really fast, thanks a lot for the prompt response and implementation! will check it out ASAP