Single-Producer Single-Consumer Lock-Free FIFO
include/structures/spsc_fifo.h View source View on GitHubStructs
Section titled “Structs”spsc_fifo
Section titled “spsc_fifo”struct spsc_fifo {
_Atomic size_t head;
_Atomic size_t tail;
size_t size;
size_t mask;
uint8_t *data;
}; Functions
Section titled “Functions”spsc_fifo_init
Section titled “spsc_fifo_init”bool spsc_fifo_init(struct spsc_fifo *fifo, size_t size); spsc_fifo_init_with
Section titled “spsc_fifo_init_with”void spsc_fifo_init_with(struct spsc_fifo *fifo, void *buffer, size_t size); spsc_fifo_destroy
Section titled “spsc_fifo_destroy”void spsc_fifo_destroy(struct spsc_fifo *fifo); spsc_fifo_write
Section titled “spsc_fifo_write”size_t spsc_fifo_write(struct spsc_fifo *fifo, const void *src, size_t len); spsc_fifo_read
Section titled “spsc_fifo_read”size_t spsc_fifo_read(struct spsc_fifo *fifo, void *dst, size_t len); spsc_fifo_peek
Section titled “spsc_fifo_peek”size_t spsc_fifo_peek(const struct spsc_fifo *fifo, void *dst, size_t len); spsc_fifo_push_ptr
Section titled “spsc_fifo_push_ptr”bool spsc_fifo_push_ptr(struct spsc_fifo *fifo, const void *ptr); spsc_fifo_pop_ptr
Section titled “spsc_fifo_pop_ptr”bool spsc_fifo_pop_ptr(struct spsc_fifo *fifo, void **out_ptr); spsc_fifo_len
Section titled “spsc_fifo_len”size_t spsc_fifo_len(const struct spsc_fifo *fifo); spsc_fifo_avail
Section titled “spsc_fifo_avail”size_t spsc_fifo_avail(const struct spsc_fifo *fifo); spsc_fifo_is_empty
Section titled “spsc_fifo_is_empty”bool spsc_fifo_is_empty(const struct spsc_fifo *fifo); spsc_fifo_is_full
Section titled “spsc_fifo_is_full”bool spsc_fifo_is_full(const struct spsc_fifo *fifo); spsc_fifo_reset
Section titled “spsc_fifo_reset”void spsc_fifo_reset(struct spsc_fifo *fifo); Macros
Section titled “Macros”SPSC_FIFO_INIT
Section titled “SPSC_FIFO_INIT”#define SPSC_FIFO_INIT \
(struct spsc_fifo) { \
.head = 0, .tail = 0, .size = 0, .mask = 0, .data = NULL \
}