10 using ll_ringbuffer_t
= struct ll_ringbuffer
;
12 struct ll_ringbuffer_data
{
16 using ll_ringbuffer_data_pair
= std::pair
<ll_ringbuffer_data
,ll_ringbuffer_data
>;
17 using ll_ringbuffer_data_t
= struct ll_ringbuffer_data
;
21 * Create a new ringbuffer to hold at least `sz' elements of `elem_sz' bytes.
22 * The number of elements is rounded up to the next power of two (even if it is
23 * already a power of two, to ensure the requested amount can be written).
25 ll_ringbuffer_t
*ll_ringbuffer_create(size_t sz
, size_t elem_sz
, int limit_writes
);
26 /** Free all data associated with the ringbuffer `rb'. */
27 void ll_ringbuffer_free(ll_ringbuffer_t
*rb
);
28 /** Reset the read and write pointers to zero. This is not thread safe. */
29 void ll_ringbuffer_reset(ll_ringbuffer_t
*rb
);
32 * The non-copying data reader. Returns two ringbuffer data pointers that hold
33 * the current readable data at `rb'. If the readable data is in one segment
34 * the second segment has zero length.
36 ll_ringbuffer_data_pair
ll_ringbuffer_get_read_vector(const ll_ringbuffer_t
*rb
);
38 * The non-copying data writer. Returns two ringbuffer data pointers that hold
39 * the current writeable data at `rb'. If the writeable data is in one segment
40 * the second segment has zero length.
42 ll_ringbuffer_data_pair
ll_ringbuffer_get_write_vector(const ll_ringbuffer_t
*rb
);
45 * Return the number of elements available for reading. This is the number of
46 * elements in front of the read pointer and behind the write pointer.
48 size_t ll_ringbuffer_read_space(const ll_ringbuffer_t
*rb
);
50 * The copying data reader. Copy at most `cnt' elements from `rb' to `dest'.
51 * Returns the actual number of elements copied.
53 size_t ll_ringbuffer_read(ll_ringbuffer_t
*rb
, void *dest
, size_t cnt
);
55 * The copying data reader w/o read pointer advance. Copy at most `cnt'
56 * elements from `rb' to `dest'. Returns the actual number of elements copied.
58 size_t ll_ringbuffer_peek(ll_ringbuffer_t
*rb
, void *dest
, size_t cnt
);
59 /** Advance the read pointer `cnt' places. */
60 void ll_ringbuffer_read_advance(ll_ringbuffer_t
*rb
, size_t cnt
);
63 * Return the number of elements available for writing. This is the number of
64 * elements in front of the write pointer and behind the read pointer.
66 size_t ll_ringbuffer_write_space(const ll_ringbuffer_t
*rb
);
68 * The copying data writer. Copy at most `cnt' elements to `rb' from `src'.
69 * Returns the actual number of elements copied.
71 size_t ll_ringbuffer_write(ll_ringbuffer_t
*rb
, const void *src
, size_t cnt
);
72 /** Advance the write pointer `cnt' places. */
73 void ll_ringbuffer_write_advance(ll_ringbuffer_t
*rb
, size_t cnt
);
75 #endif /* RINGBUFFER_H */