PixelKey
NeoPixel USB Key
Loading...
Searching...
No Matches
ring_buffer.h
Go to the documentation of this file.
1#ifndef RING_BUFFER_H
2#define RING_BUFFER_H
3
4#include <stdlib.h>
5#include <stdint.h>
6#include <stdbool.h>
7
16typedef struct st_ring_buffer
17{
18 void ** p_data;
19 size_t length;
20 size_t head_idx;
21 size_t tail_idx;
23
24void ring_buffer_init(ring_buffer_t * p_buffer, void * ptr_array, size_t length);
25void * ring_buffer_peek(ring_buffer_t * p_buffer);
26bool ring_buffer_pop(ring_buffer_t * p_buffer, void ** p_element);
27bool ring_buffer_push(ring_buffer_t * p_buffer, void * p_element);
28bool ring_buffer_is_empty(ring_buffer_t * p_buffer);
29size_t ring_buffer_count(ring_buffer_t * p_buffer);
30
33#endif
size_t ring_buffer_count(ring_buffer_t *p_buffer)
Get the number of elements currently in the ring buffer.
Definition: ring_buffer.c:116
bool ring_buffer_push(ring_buffer_t *p_buffer, void *p_element)
Pushes a value onto the ring buffer.
Definition: ring_buffer.c:86
bool ring_buffer_is_empty(ring_buffer_t *p_buffer)
Gets whether or not the ring buffer is empty.
Definition: ring_buffer.c:106
void * ring_buffer_peek(ring_buffer_t *p_buffer)
Gets a pointer to the next element in the buffer without removing it.
Definition: ring_buffer.c:36
void ring_buffer_init(ring_buffer_t *p_buffer, void *ptr_array, size_t length)
Initialize a ring buffer.
Definition: ring_buffer.c:23
bool ring_buffer_pop(ring_buffer_t *p_buffer, void **p_element)
Removes an element from the ring buffer.
Definition: ring_buffer.c:54
Ring buffer control struct.
Definition: ring_buffer.h:17
size_t head_idx
Index to the head of the ring buffer.
Definition: ring_buffer.h:20
size_t tail_idx
Index to the tail of the ring buffer.
Definition: ring_buffer.h:21
void ** p_data
Pointer to the underlying data region.
Definition: ring_buffer.h:18
size_t length
Number of elements in the buffer.
Definition: ring_buffer.h:19