24 lines
No EOL
612 B
C
24 lines
No EOL
612 B
C
/* SPDX-License-Identifier: MIT */
|
|
|
|
#include "ringbuf.h"
|
|
|
|
void rb_init(struct RingBuf *rb, int capacity, void *(*alloc)(int),
|
|
int struct_size) {
|
|
rb->struct_size = struct_size;
|
|
rb->capacity = capacity;
|
|
rb->write_idx = 0;
|
|
rb->read_idx = 0;
|
|
rb->buffer = alloc(capacity * struct_size); /* Calloc? */
|
|
}
|
|
|
|
void rb_destroy(struct RingBuf *rb, int(free)(void *)) { free(rb->buffer); }
|
|
|
|
enum WriteResult rb_push(struct RingBuf *rb, void *data[], int amount) {
|
|
if (rb->write_idx == rb->read_idx) {
|
|
return CollisionError;
|
|
}
|
|
|
|
// Iterate over the data and copy it to the buffer
|
|
|
|
return Ok;
|
|
} |