64 buffer_(new cell_t [buffer_size]),
68 if(!((buffer_size >= 2) && ((buffer_size & (buffer_size - 1)) == 0)))
69 throw spdlog_ex(
"async logger queue size must be power of two");
72 buffer_[i].sequence_.store(i, std::memory_order_relaxed);
86 size_t pos =
enqueue_pos_.load(std::memory_order_relaxed);
90 size_t seq = cell->
sequence_.load(std::memory_order_acquire);
91 intptr_t dif =
static_cast<intptr_t
>(seq) - static_cast<intptr_t>(pos);
94 if (
enqueue_pos_.compare_exchange_weak(pos, pos + 1, std::memory_order_relaxed))
107 cell->sequence_.store(pos + 1, std::memory_order_release);
114 size_t pos =
dequeue_pos_.load(std::memory_order_relaxed);
119 cell->
sequence_.load(std::memory_order_acquire);
120 intptr_t dif =
static_cast<intptr_t
>(seq) - static_cast<intptr_t>(pos + 1);
123 if (
dequeue_pos_.compare_exchange_weak(pos, pos + 1, std::memory_order_relaxed))
132 cell->sequence_.store(pos +
buffer_mask_ + 1, std::memory_order_release);
138 size_t first_pos =
dequeue_pos_.load(std::memory_order_relaxed);
139 size_t last_pos =
enqueue_pos_.load(std::memory_order_relaxed);
140 if (last_pos <= first_pos)
142 auto size = last_pos - first_pos;
void operator=(mpmc_bounded_queue const &)=delete
std::atomic< size_t > enqueue_pos_
size_t const buffer_mask_
static size_t const cacheline_size
mpmc_bounded_queue(size_t buffer_size)
fmt::BufferedFile & move(fmt::BufferedFile &f)
std::atomic< size_t > dequeue_pos_
char cacheline_pad_t[cacheline_size]
std::atomic< size_t > sequence_