summaryrefslogtreecommitdiff
path: root/src/shared/container
diff options
context:
space:
mode:
authordzwdz2022-08-23 19:15:59 +0200
committerdzwdz2022-08-23 19:15:59 +0200
commit38cf66edaacc4e58b561bea8a77abfd3facf59fe (patch)
tree2e9ff33e195078fdcd454607082064e949b29bd4 /src/shared/container
parent03c5dd9462492e291c6a49b88e1cd9ab34d86b6f (diff)
shared/ring: rename ring_size to ring_used, add ring_avail
Diffstat (limited to 'src/shared/container')
-rw-r--r--src/shared/container/ring.c6
-rw-r--r--src/shared/container/ring.h5
2 files changed, 9 insertions, 2 deletions
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++)
diff --git a/src/shared/container/ring.h b/src/shared/container/ring.h
index bc978ce..4f0d310 100644
--- a/src/shared/container/ring.h
+++ b/src/shared/container/ring.h
@@ -8,7 +8,10 @@ typedef struct {
size_t _head, _tail;
} ring_t;
-size_t ring_size(ring_t*);
+/** Returns amount of bytes stored in the buffer. */
+size_t ring_used(ring_t*);
+/** Returns amount of space left in the buffer. */
+size_t ring_avail(ring_t*);
void ring_put(ring_t*, void*, size_t);
void ring_put1b(ring_t*, uint8_t);