--- libelwix/src/ring.c 2026/05/05 16:25:44 1.9 +++ libelwix/src/ring.c 2026/07/27 21:11:07 1.10 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: ring.c,v 1.9 2026/05/05 16:25:44 misho Exp $ +* $Id: ring.c,v 1.10 2026/07/27 21:11:07 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -214,10 +214,11 @@ rbuf_enqueue(ringbuf_t *rbuf, void *data, size_t len, * * @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) +rbuf_dequeue(ringbuf_t *rbuf, struct iovec **out, int peek) { int h, t, n, f; @@ -234,12 +235,15 @@ rbuf_dequeue(ringbuf_t *rbuf, struct iovec **out) n = (t + 1) % rbuf->rb_bufnum; + if (out) + *out = rbuf->rb_buffer + t; + + if (peek) + break; + f = t; if (atomic_compare_exchange_weak_explicit((atomic_int*) &rbuf->rb_tail, &f, n, memory_order_release, memory_order_relaxed)) { - if (out) - *out = rbuf->rb_buffer + t; - atomic_store_explicit((atomic_int*) &rbuf->rb_full, 0, memory_order_release); break; } @@ -478,10 +482,11 @@ lrb_getr(lrbuf_t *lrb, 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) +lrb_dequeue(lrbuf_t *lrb, void *data, size_t len, int peek) { int h, t, t2, n, l, f; @@ -520,6 +525,9 @@ lrb_dequeue(lrbuf_t *lrb, void *data, size_t len) } t2 = l - n; } + + if (peek) + return l; n = t; if (atomic_compare_exchange_weak_explicit((atomic_int*) &lrb->lrb_tail,