--- libelwix/inc/elwix/aring.h 2026/02/18 01:23:04 1.7.2.1 +++ libelwix/inc/elwix/aring.h 2026/02/18 11:41:47 1.9 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: aring.h,v 1.7.2.1 2026/02/18 01:23:04 misho Exp $ +* $Id: aring.h,v 1.9 2026/02/18 11:41:47 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -51,6 +51,7 @@ SUCH DAMAGE. typedef struct { E_ATOMIC_ALIGN int rb_head; E_ATOMIC_ALIGN int rb_tail; + E_ATOMIC_ALIGN unsigned int rb_full; int rb_bufnum; struct iovec *rb_buffer; } ringbuf_t; @@ -68,7 +69,8 @@ typedef struct { _t = atomic_load_explicit((atomic_int*) &(x)->rb_tail, memory_order_acquire); \ _h = atomic_load_explicit((atomic_int*) &(x)->rb_head, memory_order_relaxed); \ if (_h == _t) \ - (r) = 0; \ + (r) = atomic_load_explicit((atomic_int*) &(x)->rb_full, memory_order_acquire) ? \ + (x)->rb_bufnum : 0; \ else \ (r) = (_h + (x)->rb_bufnum - _t) % (x)->rb_bufnum; \ } while (0) @@ -155,9 +157,10 @@ int rbuf_isfull(ringbuf_t *rbuf); * @rbuf = Ring buffer * @data = Data * @len = Length + * @lost = Permit to lost data * return: -1 error, 1 can't add data, buffer is full or 0 ok */ -int rbuf_enqueue(ringbuf_t *rbuf, void *data, size_t len); +int rbuf_enqueue(ringbuf_t *rbuf, void *data, size_t len, int lost); /* * rbuf_dequeue() - Dequeue data from buffer *