--- libelwix/src/ring.c 2026/02/10 15:49:08 1.4.4.1 +++ libelwix/src/ring.c 2026/02/10 17:24:39 1.4.4.2 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: ring.c,v 1.4.4.1 2026/02/10 15:49:08 misho Exp $ +* $Id: ring.c,v 1.4.4.2 2026/02/10 17:24:39 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -298,8 +298,9 @@ lrb_isempty(lrbuf_t *lrb) if (!lrb) return -1; - return (atomic_load_explicit((atomic_int*) &lrb->lrb_head, memory_order_acquire) == - atomic_load_explicit((atomic_int*) &lrb->lrb_tail, memory_order_acquire)); + return (!atomic_load_explicit((atomic_int*) &lrb->lrb_full, memory_order_acquire) && + (atomic_load_explicit((atomic_int*) &lrb->lrb_head, memory_order_acquire) == + atomic_load_explicit((atomic_int*) &lrb->lrb_tail, memory_order_acquire))); } /* @@ -318,6 +319,9 @@ lrb_isfull(lrbuf_t *lrb) if (!lrb->lrb_size) return 1; + if (!atomic_load_explicit((atomic_int*) &lrb->lrb_full, memory_order_acquire)) + 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) @@ -370,7 +374,8 @@ lrb_enqueue(lrbuf_t *lrb, void *data, size_t len, int n = len - n; } - atomic_store_explicit((atomic_int*) &lrb->lrb_head, n, memory_order_release); + h = n; + atomic_store_explicit((atomic_int*) &lrb->lrb_head, h, memory_order_release); if (drop > 0) while (42) { n = t; @@ -380,6 +385,9 @@ lrb_enqueue(lrbuf_t *lrb, void *data, size_t len, int t = n; t2 = (t + drop) % lrb->lrb_size; } + else + t2 = atomic_load_explicit((atomic_int*) &lrb->lrb_tail, memory_order_acquire); + atomic_store_explicit((atomic_int*) &lrb->lrb_full, (h == t2), memory_order_release); return 0; } @@ -430,8 +438,10 @@ lrb_dequeue(lrbuf_t *lrb, void *data, size_t len) n = t; if (atomic_compare_exchange_weak_explicit((atomic_int*) &lrb->lrb_tail, - &n, t2, memory_order_release, memory_order_relaxed)) + &n, t2, memory_order_release, memory_order_relaxed)) { + atomic_store_explicit((atomic_int*) &lrb->lrb_full, 0, memory_order_release); return l; + } } return 0;