5#ifndef SPA_RINGBUFFER_H
6#define SPA_RINGBUFFER_H
36#define SPA_RINGBUFFER_INIT() ((struct spa_ringbuffer) { 0, 0 })
72 *index = __atomic_load_n(&rbuf->
readindex, __ATOMIC_RELAXED);
73 return (int32_t) (__atomic_load_n(&rbuf->
writeindex, __ATOMIC_ACQUIRE) - *index);
89 const void *buffer, uint32_t size,
90 uint32_t offset,
void *data, uint32_t len)
92 uint32_t l0 =
SPA_MIN(len, size - offset), l1 = len - l0;
106 __atomic_store_n(&rbuf->
readindex, index, __ATOMIC_RELEASE);
122 *index = __atomic_load_n(&rbuf->
writeindex, __ATOMIC_RELAXED);
123 return (int32_t) (*index - __atomic_load_n(&rbuf->
readindex, __ATOMIC_ACQUIRE));
139 void *buffer, uint32_t size,
140 uint32_t offset,
const void *data, uint32_t len)
142 uint32_t l0 =
SPA_MIN(len, size - offset), l1 = len - l0;
156 __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:61
static void spa_ringbuffer_init(struct spa_ringbuffer *rbuf)
Initialize a spa_ringbuffer with size.
Definition ringbuffer.h:50
static void spa_ringbuffer_read_update(struct spa_ringbuffer *rbuf, int32_t index)
Update the read pointer to index.
Definition ringbuffer.h:111
#define SPA_RINGBUFFER_INIT()
Definition ringbuffer.h:43
static void spa_ringbuffer_write_update(struct spa_ringbuffer *rbuf, int32_t index)
Update the write pointer to index.
Definition ringbuffer.h:161
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:95
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:77
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:145
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:127
#define SPA_MIN(a, b)
Definition defs.h:165
#define SPA_UNUSED
Definition defs.h:297
#define SPA_UNLIKELY(x)
Definition defs.h:359
#define spa_memcpy(d, s, n)
Definition defs.h:481
#define SPA_PTROFF(ptr_, offset_, type_)
Return the address (buffer + offset) as pointer of type.
Definition defs.h:212
A ringbuffer type.
Definition ringbuffer.h:37
uint32_t readindex
Definition ringbuffer.h:38
uint32_t writeindex
Definition ringbuffer.h:39