14 assert((
capacity > 1) &&
"Ring queue capacity must be greater than one!");
15 assert(((
capacity & (
capacity - 1)) == 0) &&
"Ring queue capacity must be a power of two!");
17 memset(_pad0, 0,
sizeof(cache_line_pad));
18 memset(_pad1, 0,
sizeof(cache_line_pad));
19 memset(_pad2, 0,
sizeof(cache_line_pad));
20 memset(_pad3, 0,
sizeof(cache_line_pad));
26 const size_t head = _head.load(std::memory_order_acquire);
27 const size_t tail = _tail.load(std::memory_order_acquire);
36 return Enqueue(std::forward<T>(temp));
42 const size_t head = _head.load(std::memory_order_relaxed);
43 const size_t tail = _tail.load(std::memory_order_acquire);
46 if (((head - tail + 1) & _mask) == 0)
50 _buffer[head & _mask] = std::move(item);
53 _head.store(head + 1, std::memory_order_release);
61 const size_t tail = _tail.load(std::memory_order_relaxed);
62 const size_t head = _head.load(std::memory_order_acquire);
65 if (((head - tail) & _mask) == 0)
69 item = std::move(_buffer[tail & _mask]);
72 _tail.store(tail + 1, std::memory_order_release);
bool Enqueue(const T &item)
Enqueue an item into the ring queue (single producer thread method)
size_t size() const noexcept
Get ring queue size.
size_t capacity() const noexcept
Get ring queue capacity.
SPSCRingQueue(size_t capacity)
Default class constructor.
bool Dequeue(T &item)
Dequeue an item from the ring queue (single consumer thread method)
C++ Common project definitions.