20 #ifndef _pbd_mpc_queue_h_
21 #define _pbd_mpc_queue_h_
28 # define MPMC_QUEUE_TYPE std::atomic<size_t>
61 for (power_of_two = 1; 1U << power_of_two < sz; ++power_of_two) ;
62 return 1U << power_of_two;
69 assert ((buffer_size >= 2) && ((buffer_size & (buffer_size - 1)) == 0));
93 size_t pos =
_enqueue_pos.load (std::memory_order_relaxed);
97 size_t seq = cell->
_sequence.load (std::memory_order_acquire);
98 intptr_t dif = (intptr_t)seq - (intptr_t)pos;
100 if (
_enqueue_pos.compare_exchange_weak (pos, pos + 1, std::memory_order_relaxed))
104 }
else if (dif < 0) {
112 cell->
_sequence.store (pos + 1, std::memory_order_release);
121 size_t pos =
_dequeue_pos.load (std::memory_order_relaxed);
125 size_t seq = cell->
_sequence.load (std::memory_order_acquire);
126 intptr_t dif = (intptr_t)seq - (intptr_t) (pos + 1);
128 if (
_dequeue_pos.compare_exchange_weak (pos, pos + 1, std::memory_order_relaxed))
132 }
else if (dif < 0) {
162 #undef MPMC_QUEUE_TYPE
char _pad2[64 - sizeof(size_t)]
std::atomic< size_t > _enqueue_pos
static size_t power_of_two_size(size_t sz)
void reserve(size_t buffer_size)
bool push_back(T const &data)
MPMCQueue(size_t buffer_size=8)
std::atomic< size_t > _dequeue_pos
char _pad1[64 - sizeof(cell_t *) - sizeof(size_t)]
char _pad3[64 - sizeof(size_t)]
std::atomic< size_t > _sequence