I am searching for a ringbuffer-implementation in C in userspace, so I can use it in my library.
Because I need a ringbuffer with
- non-blocked write (=overwrite oldest data)
- blocked read if empty
I searched a while and remembered I have used wait_event_interruptible & wake_up_interruptible to do something like this in kernel-mode.
But what is used in user-space so I maybe can search for a ringbuffer in combination with that method? I don’t want to re-invent the wheel – there are many ringbuffer-solutions around.
Thanks in advance & with kind regards!
EDIT:
It seems that maybe pthread_cond_wait could be an equivalent of wait_event_interruptible.
Adding another answer with some code, which isn’t 1:1 match to pseudocde in my other answer. Marking this as wiki answer, in case someone want’s to add comments or do other improvements. C phtread mutex+condition variable implementation of very simple ringbuffer: