From 38cf66edaacc4e58b561bea8a77abfd3facf59fe Mon Sep 17 00:00:00 2001 From: dzwdz Date: Tue, 23 Aug 2022 19:15:59 +0200 Subject: shared/ring: rename ring_size to ring_used, add ring_avail --- src/shared/container/ring.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/shared/container/ring.c') diff --git a/src/shared/container/ring.c b/src/shared/container/ring.c index 67944b0..21c63a1 100644 --- a/src/shared/container/ring.c +++ b/src/shared/container/ring.c @@ -7,13 +7,17 @@ static bool at_end(ring_t *r) { || (r->_head + 1 == r->capacity && r->_tail == 0); } -size_t ring_size(ring_t *r) { +size_t ring_used(ring_t *r) { if (r->_head >= r->_tail) return r->_head - r->_tail; else return r->_head + r->capacity - r->_tail; } +size_t ring_avail(ring_t *r) { + return r->capacity - ring_used(r); +} + void ring_put(ring_t *r, void *buf, size_t len) { // TODO do something similar to ring_get for (size_t i = 0; i < len; i++) -- cgit v1.2.3