FrostWing
A lightweight raw-control operating system.
Loading...
Searching...
No Matches
ringbuffer.h
Go to the documentation of this file.
1
11#ifndef RINGBUFFER_H
12#define RINGBUFFER_H
13
14#include <basics.h>
15
20typedef struct {
21 uint8_t* buffer; // Pointer to raw memory buffer
22 size_t capacity; // Max number of elements
23 size_t elem_size; // Size of each element in bytes
24
25 size_t head; // Write position
26 size_t tail; // Read position
27 size_t count; // Number of elements stored
29
38void rb_init(ring_buffer_t* rb, void* buffer, size_t capacity, size_t elem_size);
39
46int rb_full(const ring_buffer_t* rb);
47
54int rb_empty(const ring_buffer_t* rb);
55
63int rb_push(ring_buffer_t* rb, const void* data);
64
72int rb_pop(ring_buffer_t* rb, void* out);
73
81int rb_peek(const ring_buffer_t* rb, void* out);
82
89
96size_t rb_size(const ring_buffer_t* rb);
97
104size_t rb_free(const ring_buffer_t* rb);
105
106#endif
This is a basic header files with FrostWing specific short forms and basically a good for life header...
int rb_peek(const ring_buffer_t *rb, void *out)
Peek at the next element without removing it.
int rb_empty(const ring_buffer_t *rb)
Check if buffer is empty.
size_t rb_free(const ring_buffer_t *rb)
Get remaining capacity.
int rb_push(ring_buffer_t *rb, const void *data)
Push an element into the buffer.
int rb_pop(ring_buffer_t *rb, void *out)
Pop an element from the buffer.
int rb_full(const ring_buffer_t *rb)
Check if buffer is full.
size_t rb_size(const ring_buffer_t *rb)
Get number of elements currently stored.
void rb_init(ring_buffer_t *rb, void *buffer, size_t capacity, size_t elem_size)
Initialize a ring buffer.
void rb_clear(ring_buffer_t *rb)
Clear the buffer.
Structure representing a ring buffer.
Definition ringbuffer.h:20