33 unsigned int readi = atomic_load(&rb->
readi);
36 assert(readi < rb->buf_len);
38 if (readi == atomic_load(&rb->
writei))
42 atomic_signal_fence(memory_order_seq_cst);
47 atomic_store(&rb->
readi, readi);
54 return atomic_load(&rb->
readi) == atomic_load(&rb->
writei);
60 unsigned int writei = atomic_load(&rb->
writei);
61 unsigned int old_writei = writei;
66 if (writei == atomic_load(&rb->
readi))
69 rb->
bufp[old_writei] = d;
70 atomic_signal_fence(memory_order_seq_cst);
71 atomic_store(&rb->
writei, writei);
void ringbuf_putchar(void *rb, char c)
Insert a character into the ring buffer.
int ringbuf_get(ringbuf_t *rb)
Extract a byte from the ring buffer.
bool ringbuf_empty(ringbuf_t *rb)
Test whether the ring buffer contains any data.
bool ringbuf_put(ringbuf_t *rb, uint8_t d)
Insert a byte into the ring buffer.
void ringbuf_init(ringbuf_t *rb, void *bufp, size_t buf_len)
Runtime initializer for a ring buffer descriptor.