#include <libcork/ds.h>
A ring buffer data structure that can be easily embedded into other types. All of the fields in cork_ring_buffer are private; you should only access the contents of the ring buffer via the functions defined below.
The elements of a ring buffer are void * pointers. (You can also store integers via the intptr_t and uintptr_t types.) Ring buffers have a fixed capacity, which must be specified when the ring buffer instance is initialized. You cannot add extra space to an existing ring buffer.
Ring buffers implement a FIFO queue structure; elements will be returned by cork_ring_buffer_pop() in the same order that they’re added by cork_ring_buffer_add().
Initializes a ring buffer instance, having a capacity of size elements. If we cannot initialize the ring buffer, we’ll return 1.
Finalizes a ring buffer instance. Nothing special is done to any remaining elements in the ring buffer; if they need to be finalized, you should do that yourself before calling this function.
Returns whether the ring buffer is empty or full. (You cannot add elements to a full ring buffer, and you cannot pop elemenst from an empty one.)
Adds element to a ring buffer. If the ring buffer is full, we return -1, and the ring buffer will be unchanged. Otherwise we return 0.
Returns the next element in the ring buffer. If the ring buffer is empty, we return NULL. The _pop variant will remove the returned element from the ring buffer before returning it; the _peek variant will leave the element in the ring buffer.