2024-06-23 14:08:57 +02:00
|
|
|
/* SPDX-License-Identifier: MIT */
|
|
|
|
|
2024-06-23 14:15:56 +02:00
|
|
|
/**
|
2024-06-23 14:08:57 +02:00
|
|
|
* 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 */
|
2024-06-23 14:15:56 +02:00
|
|
|
enum WriteResult rb_push(struct RingBuf *rb, void *data[], int amount,
|
|
|
|
int (*memcpy)(void *, const void *, int));
|
2024-06-23 14:08:57 +02:00
|
|
|
|
|
|
|
/** Read data from the ring buffer */
|
|
|
|
// void *rb_read(struct RingBuf *rb, int amount);
|