#ifndef QUEUE_H #define QUEUE_H #include "command.h" #include /* Fixed‑size lock‑free SPSC queue (single producer, single consumer). * The queue is safe for one thread writing (producer) and one thread * reading (consumer). No locks, no dynamic memory allocation. * Must be initialised before first use. All operations are RT‑safe. */ #define QUEUE_CAPACITY 256 typedef struct { command_t buffer[QUEUE_CAPACITY]; /* head: index where next element will be written (producer only) * tail: index of next element to read (consumer only) */ int head; int tail; } spsc_queue_t; /* Initialise queue (must be called once before any push/pop). */ void queue_init(spsc_queue_t *q); /* Push a command. Returns true on success, false if queue full. */ bool queue_push(spsc_queue_t *q, command_t cmd); /* Pop a command. Returns true if a command was retrieved, false if empty. */ bool queue_pop(spsc_queue_t *q, command_t *cmd); #endif