summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared')
-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);