2023-02-08 23:00:04 +08:00
|
|
|
#pragma once
|
|
|
|
|
2023-02-13 04:30:18 +08:00
|
|
|
#include "arch.h" // For size_t
|
2023-02-08 23:00:04 +08:00
|
|
|
|
|
|
|
// Single producer, single consumer non-blocking queue
|
2023-05-17 05:08:48 +08:00
|
|
|
|
2023-02-08 23:00:04 +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-08 23:00:04 +08:00
|
|
|
};
|
|
|
|
|
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
|