ringbuf/ringbuf.h
2024-06-23 14:08:57 +02:00

24 lines
No EOL
720 B
C

/* SPDX-License-Identifier: MIT */
/**
* Ring buffer, also known as circular buffer.
*/
struct RingBuf {
int struct_size; /* Size of the struct */
int capacity; /* The physical capacity of the entire ringbuf */
int write_idx; /* The write head */
int read_idx; /* THe read head */
void **buffer; /* The actual data */
};
enum WriteResult { CollisionError, Ok };
/** Initialize the ring buffer */
void rb_init(struct RingBuf *rb, int capacity, void *(*alloc)(int),
int struct_size);
/** Insert data to the ring buffer */
enum WriteResult rb_push(struct RingBuf *rb, void *data[], int amount);
/** Read data from the ring buffer */
// void *rb_read(struct RingBuf *rb, int amount);