numerical-collection-cpp 0.10.0
A collection of algorithms in numerical analysis implemented in C++
|
Class of a queue using a circular buffer and thread-safe for a single producer thread and a single consumer thread. More...
#include <num_collect/util/producer_consumer_circular_queue.h>
Public Member Functions | |
producer_consumer_circular_queue (const producer_consumer_circular_queue &)=delete | |
producer_consumer_circular_queue (index_type size) | |
Constructor. | |
producer_consumer_circular_queue (producer_consumer_circular_queue &&)=delete | |
~producer_consumer_circular_queue () noexcept | |
Destructor. | |
auto | operator= (const producer_consumer_circular_queue &)=delete |
auto | operator= (producer_consumer_circular_queue &&)=delete |
template<typename... Args> | |
auto | try_emplace (Args &&... args) noexcept(std::is_nothrow_constructible_v< T, Args... >) -> bool |
Try to push an element constructing in-place. | |
auto | try_ignore () noexcept -> bool |
Try to pop an element without getting the element. | |
template<typename Output > | |
auto | try_pop (Output &output) noexcept(noexcept(output=std::move(std::declval< T & >()))) -> bool |
Try to pop an element. | |
Private Types | |
using | storage_type = object_storage<T, cache_line> |
Type of storage. | |
Private Member Functions | |
auto | increment (storage_type *ptr) noexcept -> storage_type * |
Increment a pointer with consideration of the loop of the buffer. | |
Static Private Member Functions | |
static auto | get_buffer_size (index_type val) -> std::size_t |
Validate a size and get the size of the buffer. | |
Private Attributes | |
storage_type * | begin_ |
Beginning of the buffer. | |
std::atomic< storage_type * > | consumer_pos_ |
Position of the consumer. | |
storage_type * | end_ |
Past-the-end pointer of the buffer. | |
std::atomic< storage_type * > | producer_pos_ |
Position of the producer. | |
Class of a queue using a circular buffer and thread-safe for a single producer thread and a single consumer thread.
T | Type of elements in the queue. |
Definition at line 47 of file producer_consumer_circular_queue.h.
|
private |
Type of storage.
Definition at line 141 of file producer_consumer_circular_queue.h.
|
inlineexplicit |
Constructor.
[in] | size | Size. |
Definition at line 54 of file producer_consumer_circular_queue.h.
|
inlinenoexcept |
Destructor.
Definition at line 64 of file producer_consumer_circular_queue.h.
|
inlinestaticnodiscardprivate |
Validate a size and get the size of the buffer.
[in] | val | Size of the queue. |
Definition at line 149 of file producer_consumer_circular_queue.h.
|
inlinenodiscardprivatenoexcept |
Increment a pointer with consideration of the loop of the buffer.
[in] | ptr | Pointer. |
Definition at line 163 of file producer_consumer_circular_queue.h.
|
inlinenodiscardnoexcept |
Try to push an element constructing in-place.
Args | Types of arguments of the constructor. |
[in] | args | Arguments of the constructor. |
Definition at line 85 of file producer_consumer_circular_queue.h.
|
inlinenodiscardnoexcept |
Try to pop an element without getting the element.
Definition at line 127 of file producer_consumer_circular_queue.h.
|
inlinenodiscardnoexcept |
Try to pop an element.
Output | Type of the variable to pop to. |
[in] | output | Variable to pop to. |
Definition at line 108 of file producer_consumer_circular_queue.h.
|
private |
Beginning of the buffer.
Definition at line 173 of file producer_consumer_circular_queue.h.
|
private |
Position of the consumer.
Consumer will read the next object here.
Definition at line 190 of file producer_consumer_circular_queue.h.
|
private |
Past-the-end pointer of the buffer.
Definition at line 176 of file producer_consumer_circular_queue.h.
|
private |
Position of the producer.
Producer will write the next object here.
Definition at line 183 of file producer_consumer_circular_queue.h.