summaryrefslogtreecommitdiff
path: root/src/shared/container/ring.h
blob: 4f0d310d7ace7863aa1d1dd8cb77960e035b9b2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#pragma once
#include <stddef.h>
#include <stdint.h>

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*, 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);