--- libelwix/src/ring.c 2026/02/10 17:24:39 1.4.4.2 +++ libelwix/src/ring.c 2026/02/10 18:23:53 1.5.2.1 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: ring.c,v 1.4.4.2 2026/02/10 17:24:39 misho Exp $ +* $Id: ring.c,v 1.5.2.1 2026/02/10 18:23:53 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -284,6 +284,7 @@ lrb_purge(lrbuf_t *lrb) atomic_store_explicit((atomic_int*) &lrb->lrb_head, 0, memory_order_relaxed); atomic_store_explicit((atomic_int*) &lrb->lrb_tail, 0, memory_order_relaxed); + atomic_store_explicit((atomic_int*) &lrb->lrb_full, 0, memory_order_relaxed); } /* @@ -323,10 +324,7 @@ lrb_isfull(lrbuf_t *lrb) return 0; t = atomic_load_explicit((atomic_int*) &lrb->lrb_tail, memory_order_acquire); - h = atomic_load_explicit((atomic_int*) &lrb->lrb_head, memory_order_relaxed) + 1; - if (h >= lrb->lrb_size) - h ^= h; - + h = atomic_load_explicit((atomic_int*) &lrb->lrb_head, memory_order_acquire); return (h == t); } @@ -342,7 +340,7 @@ lrb_isfull(lrbuf_t *lrb) int lrb_enqueue(lrbuf_t *lrb, void *data, size_t len, int lost) { - int h, t, n, t2, unused, drop = 0; + int h, t = 0, n, t2 = 0, unused, drop = 0; if (!lrb || !lrb->lrb_data) return -1; @@ -402,7 +400,7 @@ lrb_enqueue(lrbuf_t *lrb, void *data, size_t len, int int lrb_dequeue(lrbuf_t *lrb, void *data, size_t len) { - int h, t, t2, n, l; + int h, t, t2, n, l, f; if (!lrb) return -1; @@ -414,12 +412,16 @@ lrb_dequeue(lrbuf_t *lrb, void *data, size_t len) while (42) { t = atomic_load_explicit((atomic_int*) &lrb->lrb_tail, memory_order_acquire); h = atomic_load_explicit((atomic_int*) &lrb->lrb_head, memory_order_acquire); + f = atomic_load_explicit((atomic_int*) &lrb->lrb_full, memory_order_acquire); l = h - t; if (l < 0) l += lrb->lrb_size; - if (!l) - return 0; + if (!l) { + if (!f) + return 0; + l = lrb->lrb_size; + } if (l > len) l = len;