57 end_(begin_ + (size + 1)),
58 producer_pos_(begin_),
59 consumer_pos_(begin_) {}
65 while (try_ignore()) {
84 template <
typename... Args>
86 std::is_nothrow_constructible_v<T, Args...>) ->
bool {
88 producer_pos_.load(std::memory_order::relaxed);
89 storage_type*
const next_producer_pos = increment(pushed_pos);
90 if (next_producer_pos ==
91 consumer_pos_.load(std::memory_order::acquire)) {
95 pushed_pos->
emplace(std::forward<Args>(args)...);
96 producer_pos_.store(next_producer_pos, std::memory_order::release);
107 template <
typename Output>
108 [[nodiscard]]
auto try_pop(Output& output)
noexcept(
109 noexcept(output = std::move(std::declval<T&>()))) ->
bool {
111 consumer_pos_.load(std::memory_order::relaxed);
112 if (popped_pos == producer_pos_.load(std::memory_order::acquire)) {
116 output = std::move(popped_pos->
get_ref());
118 consumer_pos_.store(increment(popped_pos), std::memory_order::release);
129 consumer_pos_.load(std::memory_order::relaxed);
130 if (popped_pos == producer_pos_.load(std::memory_order::acquire)) {
135 consumer_pos_.store(increment(popped_pos), std::memory_order::release);
150 if (val <= 0 || val == std::numeric_limits<index_type>::max()) {
154 return safe_cast<std::size_t>(val + 1);
Definition of cache_line variable.
Class of exception on invalid arguments.
Class of storage of objects.
auto get_ref() noexcept -> T &
Get the reference of the value.
void emplace(Args &&... args)
Construct an object.
void reset() noexcept
Destruct the object.
Class of a queue using a circular buffer and thread-safe for a single producer thread and a single co...
auto try_emplace(Args &&... args) noexcept(std::is_nothrow_constructible_v< T, Args... >) -> bool
Try to push an element constructing in-place.
std::atomic< storage_type * > consumer_pos_
Position of the consumer.
storage_type * end_
Past-the-end pointer of the buffer.
auto try_pop(Output &output) noexcept(noexcept(output=std::move(std::declval< T & >()))) -> bool
Try to pop an element.
static auto get_buffer_size(index_type val) -> std::size_t
Validate a size and get the size of the buffer.
auto increment(storage_type *ptr) noexcept -> storage_type *
Increment a pointer with consideration of the loop of the buffer.
producer_consumer_circular_queue(index_type size)
Constructor.
storage_type * begin_
Beginning of the buffer.
~producer_consumer_circular_queue() noexcept
Destructor.
std::atomic< storage_type * > producer_pos_
Position of the producer.
auto try_ignore() noexcept -> bool
Try to pop an element without getting the element.
Definition of exceptions.
Definition of index_type type.
Definition of macros for logging.
#define NUM_COLLECT_LOG_AND_THROW(EXCEPTION_TYPE,...)
Write an error log and throw an exception for an error.
std::ptrdiff_t index_type
Type of indices in this library.
Definition of object_storage class.
Definition of safe_cast function.