14 static_assert(Capacity > 0,
"SpscQueue capacity must be positive");
18 const std::size_t head = head_.load(std::memory_order_relaxed);
19 const std::size_t next = increment(head);
20 if(next == tail_.load(std::memory_order_acquire)) {
25 head_.store(next, std::memory_order_release);
31 const std::size_t tail = tail_.load(std::memory_order_relaxed);
32 if(tail == head_.load(std::memory_order_acquire)) {
37 tail_.store(increment(tail), std::memory_order_release);
43 return head_.load(std::memory_order_acquire) == tail_.load(std::memory_order_acquire);
48 const std::size_t next = increment(head_.load(std::memory_order_acquire));
49 return next == tail_.load(std::memory_order_acquire);
58 static constexpr std::size_t StorageSize = Capacity + 1;
63 static constexpr std::size_t CacheLineSize = 64;
65 static constexpr std::size_t increment(std::size_t value)
67 return (value + 1) % StorageSize;
70 std::array<T, StorageSize> data_{};
71 alignas(CacheLineSize) std::atomic<std::size_t> head_{0};
72 alignas(CacheLineSize) std::atomic<std::size_t> tail_{0};