This implements a ring buffer that works in "chunks", not bytes.
So you write/read a complete chunk or not at all. There are two types of ring buffer: normal and overwrite. Overwrite will reclaim the oldest chunks inorder to make way for new ones, the normal version will refuse to write a new chunk if the ring buffer is full.
This implementation is capable of working across processes, but one process must only write and the other process read.
The read process will do the following:
for (i = 0; i < 200; i++) {
try_read_again:
if (l < 0) {
goto try_read_again;
}
}
...
#define QB_RB_FLAG_CREATE
Create a ring buffer (rather than open and existing one).
Definition: qbrb.h:81
void qb_rb_close(qb_ringbuffer_t *rb)
Dereference the ringbuffer and, if we are the last user, destroy it.
ssize_t qb_rb_chunk_read(qb_ringbuffer_t *rb, void *data_out, size_t len, int32_t ms_timeout)
Read the oldest chunk into data_out.
#define QB_RB_FLAG_SHARED_PROCESS
The ringbuffer will be shared between processes.
Definition: qbrb.h:100
qb_ringbuffer_t * qb_rb_open(const char *name, size_t size, uint32_t flags, size_t shared_user_data_size)
Create the ring buffer with the given type.
The write process will do the following:
for (i = 0; i < 200; i++) {
try_write_again:
if (l < sizeof(v)) {
goto try_write_again;
}
}
...
ssize_t qb_rb_chunk_write(qb_ringbuffer_t *rb, const void *data, size_t len)
Write a chunk to the ring buffer.
- Author
- Angus Salkeld asalk.nosp@m.eld@.nosp@m.redha.nosp@m.t.co.nosp@m.m
- See also
- qbrb.h