--- libelwix/inc/elwix/aring.h 2026/02/10 15:49:08 1.4.4.1 +++ libelwix/inc/elwix/aring.h 2026/02/10 17:50:00 1.5 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: aring.h,v 1.4.4.1 2026/02/10 15:49:08 misho Exp $ +* $Id: aring.h,v 1.5 2026/02/10 17:50:00 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -58,6 +58,7 @@ typedef struct { typedef struct { E_ATOMIC_ALIGN unsigned int lrb_head; E_ATOMIC_ALIGN unsigned int lrb_tail; + E_ATOMIC_ALIGN unsigned int lrb_full; int lrb_size; unsigned char *lrb_data; } lrbuf_t; @@ -65,7 +66,11 @@ typedef struct { u_int _h, _t; \ _t = atomic_load_explicit((atomic_int*) &(x)->lrb_tail, memory_order_acquire); \ _h = atomic_load_explicit((atomic_int*) &(x)->lrb_head, memory_order_relaxed); \ - (r) = (_h + (x)->lrb_size - _t) % (x)->lrb_size; \ + if (_h == _t) \ + (r) = atomic_load_explicit((atomic_int*) &(x)->lrb_full, memory_order_acquire) ? \ + (x)->lrb_size : 0; \ + else \ + (r) = (_h + (x)->lrb_size - _t) % (x)->lrb_size; \ } while (0) #define lrb_unused(x, r) do { \ u_int _r; \