25 #ifndef SPA_RINGBUFFER_H
26 #define SPA_RINGBUFFER_H
56 #define SPA_RINGBUFFER_INIT() ((struct spa_ringbuffer) { 0, 0 })
92 *index = __atomic_load_n(&rbuf->
readindex, __ATOMIC_RELAXED);
93 return (int32_t) (__atomic_load_n(&rbuf->
writeindex, __ATOMIC_ACQUIRE) - *index);
109 const void *buffer, uint32_t size,
110 uint32_t offset,
void *data, uint32_t len)
112 uint32_t l0 =
SPA_MIN(len, size - offset), l1 = len - l0;
126 __atomic_store_n(&rbuf->
readindex, index, __ATOMIC_RELEASE);
142 *index = __atomic_load_n(&rbuf->
writeindex, __ATOMIC_RELAXED);
143 return (int32_t) (*index - __atomic_load_n(&rbuf->
readindex, __ATOMIC_ACQUIRE));
159 void *buffer, uint32_t size,
160 uint32_t offset,
const void *data, uint32_t len)
162 uint32_t l0 =
SPA_MIN(len, size - offset), l1 = len - l0;
176 __atomic_store_n(&rbuf->
writeindex, index, __ATOMIC_RELEASE);
static void spa_ringbuffer_set_avail(struct spa_ringbuffer *rbuf, uint32_t size)
Sets the pointers so that the ringbuffer contains size bytes.
Definition: ringbuffer.h:81
static void spa_ringbuffer_init(struct spa_ringbuffer *rbuf)
Initialize a spa_ringbuffer with size.
Definition: ringbuffer.h:70
static void spa_ringbuffer_read_update(struct spa_ringbuffer *rbuf, int32_t index)
Update the read pointer to index.
Definition: ringbuffer.h:131
#define SPA_RINGBUFFER_INIT()
Definition: ringbuffer.h:63
static void spa_ringbuffer_write_update(struct spa_ringbuffer *rbuf, int32_t index)
Update the write pointer to index.
Definition: ringbuffer.h:181
static void spa_ringbuffer_read_data(struct spa_ringbuffer *rbuf, const void *buffer, uint32_t size, uint32_t offset, void *data, uint32_t len)
Read len bytes from rbuf starting offset.
Definition: ringbuffer.h:115
static int32_t spa_ringbuffer_get_read_index(struct spa_ringbuffer *rbuf, uint32_t *index)
Get the read index and available bytes for reading.
Definition: ringbuffer.h:97
static void spa_ringbuffer_write_data(struct spa_ringbuffer *rbuf, void *buffer, uint32_t size, uint32_t offset, const void *data, uint32_t len)
Write len bytes to buffer starting offset.
Definition: ringbuffer.h:165
static int32_t spa_ringbuffer_get_write_index(struct spa_ringbuffer *rbuf, uint32_t *index)
Get the write index and the number of bytes inside the ringbuffer.
Definition: ringbuffer.h:147
#define SPA_MIN(a, b)
Definition: defs.h:167
#define SPA_UNLIKELY(x)
Definition: defs.h:355
#define spa_memcpy(d, s, n)
Definition: defs.h:441
#define SPA_PTROFF(ptr_, offset_, type_)
Return the address (buffer + offset) as pointer of type.
Definition: defs.h:210
A ringbuffer type.
Definition: ringbuffer.h:57
uint32_t readindex
Definition: ringbuffer.h:58
uint32_t writeindex
Definition: ringbuffer.h:59