Ensure at least the specified ringbuffer size is writable
[openal-soft.git] / Alc / ringbuffer.h
blobbcf6737477b4f0fdbb2fb45019cf0e3c034e1bae
1 #ifndef RINGBUFFER_H
2 #define RINGBUFFER_H
4 #include <stddef.h>
7 typedef struct ll_ringbuffer ll_ringbuffer_t;
8 typedef struct ll_ringbuffer_data {
9 char *buf;
10 size_t len;
11 } ll_ringbuffer_data_t;
14 /**
15 * Create a new ringbuffer to hold at least `sz' elements of `elem_sz' bytes.
16 * The number of elements is rounded up to the next power of two (even if it is
17 * already a power of two, to ensure the requested amount can be written).
19 ll_ringbuffer_t *ll_ringbuffer_create(size_t sz, size_t elem_sz, int limit_writes);
20 /** Free all data associated with the ringbuffer `rb'. */
21 void ll_ringbuffer_free(ll_ringbuffer_t *rb);
22 /** Reset the read and write pointers to zero. This is not thread safe. */
23 void ll_ringbuffer_reset(ll_ringbuffer_t *rb);
25 /**
26 * The non-copying data reader. `vec' is an array of two places. Set the values
27 * at `vec' to hold the current readable data at `rb'. If the readable data is
28 * in one segment the second segment has zero length.
30 void ll_ringbuffer_get_read_vector(const ll_ringbuffer_t *rb, ll_ringbuffer_data_t vec[2]);
31 /**
32 * The non-copying data writer. `vec' is an array of two places. Set the values
33 * at `vec' to hold the current writeable data at `rb'. If the writeable data
34 * is in one segment the second segment has zero length.
36 void ll_ringbuffer_get_write_vector(const ll_ringbuffer_t *rb, ll_ringbuffer_data_t vec[2]);
38 /**
39 * Return the number of elements available for reading. This is the number of
40 * elements in front of the read pointer and behind the write pointer.
42 size_t ll_ringbuffer_read_space(const ll_ringbuffer_t *rb);
43 /**
44 * The copying data reader. Copy at most `cnt' elements from `rb' to `dest'.
45 * Returns the actual number of elements copied.
47 size_t ll_ringbuffer_read(ll_ringbuffer_t *rb, char *dest, size_t cnt);
48 /**
49 * The copying data reader w/o read pointer advance. Copy at most `cnt'
50 * elements from `rb' to `dest'. Returns the actual number of elements copied.
52 size_t ll_ringbuffer_peek(ll_ringbuffer_t *rb, char *dest, size_t cnt);
53 /** Advance the read pointer `cnt' places. */
54 void ll_ringbuffer_read_advance(ll_ringbuffer_t *rb, size_t cnt);
56 /**
57 * Return the number of elements available for writing. This is the number of
58 * elements in front of the write pointer and behind the read pointer.
60 size_t ll_ringbuffer_write_space(const ll_ringbuffer_t *rb);
61 /**
62 * The copying data writer. Copy at most `cnt' elements to `rb' from `src'.
63 * Returns the actual number of elements copied.
65 size_t ll_ringbuffer_write(ll_ringbuffer_t *rb, const char *src, size_t cnt);
66 /** Advance the write pointer `cnt' places. */
67 void ll_ringbuffer_write_advance(ll_ringbuffer_t *rb, size_t cnt);
69 #endif /* RINGBUFFER_H */