Files

30 lines
542 B
C++
Raw Permalink Normal View History

#ifndef SPSC_QUEUE
#define SPSC_QUEUE
#include <atomic>
#include <array>
#include <cstddef>
#include "../include/command.hpp"
class SpscQueue{
public:
SpscQueue(){
head.store(0, std::memory_order_relaxed);
tail.store(0, std::memory_order_relaxed);
buffer.fill(Command{});
}
bool push(const Command&);
bool pop(Command&);
private:
std::array<Command, 64> buffer;
std::atomic<std::size_t> head;
std::atomic<std::size_t> tail;
};
#endif