/***************************************************************************** * VERSION: 1.01 * 2015-08-29 * * Single producer, single consumer ring buffer. *****************************************************************************/ #ifndef JLLIB_RINGBUF_HEADER_ #define JLLIB_RINGBUF_HEADER_ #include #include #include "jl_mem.h" typedef struct RingBuffer RingBuffer; // Create a new RingBuffer with the given capacity. RingBuffer *jlrb_new(int size); // Free the buffer. Note that the items in the buffer must be freed by the // caller before the buffer is freed. void jlrb_free(RingBuffer ** rb); // Return the total capacity of the buffer. int jlrb_size(RingBuffer * rb); // Return the number of items currently in the buffer. int jlrb_count(RingBuffer * rb); // Put the given data into the buffer. The return value is true if the put was // successful, and false if there wasn't room. bool jlrb_put(RingBuffer * rb, void *data); // Return the next item in the buffer. Returns NULL if there was no item // available. void *jlrb_get(RingBuffer * rb); #endif // JLLIB_RINGBUF_HEADER_