ringbuffer: simplify

This commit is contained in:
Wim Taymans 2017-06-22 09:49:12 +02:00
parent 5c82a03ae5
commit c391e5088a

View file

@ -36,7 +36,7 @@ struct spa_ringbuffer;
* spa_ringbuffer: * spa_ringbuffer:
* @readindex: the current read index * @readindex: the current read index
* @writeindex: the current write index * @writeindex: the current write index
* @size: the size of the ringbuffer must be power of 2 * @size: the size of the ringbuffer
* @mask: mask as @size - 1 * @mask: mask as @size - 1
*/ */
struct spa_ringbuffer { struct spa_ringbuffer {
@ -46,28 +46,18 @@ struct spa_ringbuffer {
uint32_t mask; uint32_t mask;
}; };
#define SPA_RINGBUFFER_INIT(size) (struct spa_ringbuffer) { 0, 0, (size), (size)-1 }
/** /**
* spa_ringbuffer_init: * spa_ringbuffer_init:
* @rbuf: a #struct spa_ringbuffer * @rbuf: a #struct spa_ringbuffer
* @data: pointer to an array * @size: the number of elements in the ringbuffer
* @size: the number of elements in @data
* *
* Initialize a #struct spa_ringbuffer with @data and @size. * Initialize a #struct spa_ringbuffer with @size.
* Size must be a power of 2.
*
* Returns: %SPA_RESULT_OK, unless size is not a power of 2.
*/ */
static inline int spa_ringbuffer_init(struct spa_ringbuffer *rbuf, uint32_t size) static inline void spa_ringbuffer_init(struct spa_ringbuffer *rbuf, uint32_t size)
{ {
if (SPA_UNLIKELY((size & (size - 1)) != 0)) *rbuf = SPA_RINGBUFFER_INIT(size);
return SPA_RESULT_ERROR;
rbuf->size = size;
rbuf->mask = size - 1;
rbuf->readindex = 0;
rbuf->writeindex = 0;
return SPA_RESULT_OK;
} }
/** /**