--- libelwix/inc/elwix/aring.h 2026/02/18 01:23:04 1.7.2.1 +++ libelwix/inc/elwix/aring.h 2026/07/27 21:11:07 1.10 @@ -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.10 2026/07/27 21:11:07 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,17 +157,19 @@ 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 * * @rbuf = Ring buffer * @out = Data, if =NULL, just dequeue data + * @peek = Peek only data, keep the same tail position * return: -1 error, 1 buffer is empty or 0 ok */ -int rbuf_dequeue(ringbuf_t *rbuf, struct iovec **out); +int rbuf_dequeue(ringbuf_t *rbuf, struct iovec **out, int peek); /* @@ -220,9 +224,10 @@ int lrb_enqueue(lrbuf_t *lrb, void *data, size_t len, * @lrb = Linear ring buffer * @data = Data, if =NULL, just dequeue data * @len = Length of data + * @peek = Peek only data, keep the same tail position * return: -1 error, 0 buffer is empty or >0 stored data bytes */ -int lrb_dequeue(lrbuf_t *lrb, void *data, size_t len); +int lrb_dequeue(lrbuf_t *lrb, void *data, size_t len, int peek); /* * lrb_getw() - Get address for write *