mongoose/src/queue.h

19 lines
587 B
C
Raw Normal View History

#pragma once
2023-02-13 04:30:18 +08:00
#include "arch.h" // For size_t
// Single producer, single consumer non-blocking queue
2023-05-17 05:08:48 +08:00
struct mg_queue {
char *buf;
2023-02-13 04:30:18 +08:00
size_t size;
volatile size_t tail;
volatile size_t head;
};
2023-02-13 04:30:18 +08:00
void mg_queue_init(struct mg_queue *, char *, size_t); // Init queue
size_t mg_queue_book(struct mg_queue *, char **buf, size_t); // Reserve space
void mg_queue_add(struct mg_queue *, size_t); // Add new message
size_t mg_queue_next(struct mg_queue *, char **); // Get oldest message
void mg_queue_del(struct mg_queue *, size_t); // Delete oldest message