From 642b5fb0007b64c77d186fcb018d571152ee1d47 Mon Sep 17 00:00:00 2001 From: dzwdz Date: Mon, 14 Aug 2023 18:51:07 +0200 Subject: reorganization: first steps --- src/libk/include/shared/ring.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/libk/include/shared/ring.h (limited to 'src/libk/include/shared/ring.h') diff --git a/src/libk/include/shared/ring.h b/src/libk/include/shared/ring.h new file mode 100644 index 0000000..dbaf331 --- /dev/null +++ b/src/libk/include/shared/ring.h @@ -0,0 +1,23 @@ +#pragma once +#include +#include + +typedef struct { + char *buf; + size_t capacity; + size_t _head, _tail; +} 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*, const void*, size_t); +void ring_put1b(ring_t*, uint8_t); + +size_t ring_get(ring_t*, void*, size_t); + +/** Consumes up to `len` bytes, and returns a pointer to the buffer where it's stored. + * Not thread-safe. */ +void* ring_contig(ring_t*, size_t *len); -- cgit v1.2.3