--- libelwix/src/ring.c 2025/09/26 08:58:05 1.1.2.1 +++ libelwix/src/ring.c 2025/09/26 10:13:57 1.1.2.4 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: ring.c,v 1.1.2.1 2025/09/26 08:58:05 misho Exp $ +* $Id: ring.c,v 1.1.2.4 2025/09/26 10:13:57 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -140,6 +140,8 @@ rbuf_isfull(ringbuf_t *rbuf) { if (!rbuf) return -1; + if (!rbuf->rb_bufnum) + return 1; return (((atomic_load_explicit(&rbuf->rb_head, memory_order_relaxed) + 1) % rbuf->rb_bufnum) == atomic_load_explicit(&rbuf->rb_tail, memory_order_acquire)); @@ -159,8 +161,10 @@ rbuf_enqueue(ringbuf_t *rbuf, void *data, size_t len) int h, t, n; struct iovec *iov; - if (!rbuf) + if (!rbuf || !rbuf->rb_buffer) return -1; + if (!rbuf->rb_bufnum) + return 1; h = atomic_load_explicit(&rbuf->rb_head, memory_order_relaxed); t = atomic_load_explicit(&rbuf->rb_tail, memory_order_acquire); @@ -189,8 +193,10 @@ rbuf_dequeue(ringbuf_t *rbuf, struct iovec *out) { int h, t, n; - if (!rbuf) + if (!rbuf || !rbuf->rb_buffer) return -1; + if (!rbuf->rb_bufnum) + return 1; h = atomic_load_explicit(&rbuf->rb_head, memory_order_acquire); t = atomic_load_explicit(&rbuf->rb_tail, memory_order_relaxed); @@ -200,7 +206,7 @@ rbuf_dequeue(ringbuf_t *rbuf, struct iovec *out) return 1; if (out) - out = rbuf->rb_buffer + t; + *out = rbuf->rb_buffer[t]; atomic_store_explicit(&rbuf->rb_tail, n, memory_order_release); return 0;