/* 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, int (*memcpy)(void *, const void *, int)); /** Read data from the ring buffer */ // void *rb_read(struct RingBuf *rb, int amount);