9 #ifndef CPPCOMMON_THREADS_MPMC_RING_QUEUE_H
10 #define CPPCOMMON_THREADS_MPMC_RING_QUEUE_H
49 explicit operator bool() const noexcept {
return !
empty(); }
52 bool empty() const noexcept {
return (
size() == 0); }
54 size_t capacity() const noexcept {
return _capacity; }
56 size_t size() const noexcept;
93 std::atomic<size_t> sequence;
97 typedef char cache_line_pad[128];
100 const size_t _capacity;
104 cache_line_pad _pad1;
105 std::atomic<size_t> _head;
106 cache_line_pad _pad2;
107 std::atomic<size_t> _tail;
108 cache_line_pad _pad3;
Multiple producers / multiple consumers wait-free ring queue.
MPMCRingQueue(MPMCRingQueue &&)=delete
MPMCRingQueue & operator=(const MPMCRingQueue &)=delete
MPMCRingQueue(const MPMCRingQueue &)=delete
size_t size() const noexcept
Get ring queue size.
MPMCRingQueue & operator=(MPMCRingQueue &&)=delete
size_t capacity() const noexcept
Get ring queue capacity.
bool Enqueue(const T &item)
Enqueue an item into the ring queue (multiple producers threads method)
bool Dequeue(T &item)
Dequeue an item from the ring queue (multiple consumers threads method)
MPMCRingQueue(size_t capacity)
Default class constructor.
bool empty() const noexcept
Is ring queue empty?
Multiple producers / multiple consumers wait-free ring queue inline implementation.
C++ Common project definitions.