numerical-collection-cpp 0.10.0
A collection of algorithms in numerical analysis implemented in C++
Loading...
Searching...
No Matches
num_collect::util::producer_consumer_circular_queue< T > Class Template Reference

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>

+ Collaboration diagram for num_collect::util::producer_consumer_circular_queue< T >:

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_typebegin_
 Beginning of the buffer.
 
std::atomic< storage_type * > consumer_pos_
 Position of the consumer.
 
storage_typeend_
 Past-the-end pointer of the buffer.
 
std::atomic< storage_type * > producer_pos_
 Position of the producer.
 

Detailed Description

template<typename T>
class num_collect::util::producer_consumer_circular_queue< T >

Class of a queue using a circular buffer and thread-safe for a single producer thread and a single consumer thread.

Template Parameters
TType of elements in the queue.
Thread Safety
Operations for the same object is thread safe only if a single producer thread and a single consumer thread exists.

Definition at line 47 of file producer_consumer_circular_queue.h.

Member Typedef Documentation

◆ storage_type

template<typename T >
using num_collect::util::producer_consumer_circular_queue< T >::storage_type = object_storage<T, cache_line>
private

Type of storage.

Definition at line 141 of file producer_consumer_circular_queue.h.

Constructor & Destructor Documentation

◆ producer_consumer_circular_queue()

template<typename T >
num_collect::util::producer_consumer_circular_queue< T >::producer_consumer_circular_queue ( index_type size)
inlineexplicit

Constructor.

Parameters
[in]sizeSize.

Definition at line 54 of file producer_consumer_circular_queue.h.

◆ ~producer_consumer_circular_queue()

Destructor.

Definition at line 64 of file producer_consumer_circular_queue.h.

Member Function Documentation

◆ get_buffer_size()

template<typename T >
static auto num_collect::util::producer_consumer_circular_queue< T >::get_buffer_size ( index_type val) -> std::size_t
inlinestaticnodiscardprivate

Validate a size and get the size of the buffer.

Parameters
[in]valSize of the queue.
Returns
Size of the buffer.

Definition at line 149 of file producer_consumer_circular_queue.h.

◆ increment()

template<typename T >
auto num_collect::util::producer_consumer_circular_queue< T >::increment ( storage_type * ptr) -> storage_type*
inlinenodiscardprivatenoexcept

Increment a pointer with consideration of the loop of the buffer.

Parameters
[in]ptrPointer.
Returns
Incremented pointer.

Definition at line 163 of file producer_consumer_circular_queue.h.

◆ try_emplace()

template<typename T >
template<typename... Args>
auto num_collect::util::producer_consumer_circular_queue< T >::try_emplace ( Args &&... args) -> bool
inlinenodiscardnoexcept

Try to push an element constructing in-place.

Template Parameters
ArgsTypes of arguments of the constructor.
Parameters
[in]argsArguments of the constructor.
Returns
Whether an element could be pushed.

Definition at line 85 of file producer_consumer_circular_queue.h.

◆ try_ignore()

template<typename T >
auto num_collect::util::producer_consumer_circular_queue< T >::try_ignore ( ) -> bool
inlinenodiscardnoexcept

Try to pop an element without getting the element.

Returns
Whether an element could be popped.

Definition at line 127 of file producer_consumer_circular_queue.h.

◆ try_pop()

template<typename T >
template<typename Output >
auto num_collect::util::producer_consumer_circular_queue< T >::try_pop ( Output & output) -> bool
inlinenodiscardnoexcept

Try to pop an element.

Template Parameters
OutputType of the variable to pop to.
Parameters
[in]outputVariable to pop to.
Returns
Whether an element could be popped.

Definition at line 108 of file producer_consumer_circular_queue.h.

Member Data Documentation

◆ begin_

template<typename T >
storage_type* num_collect::util::producer_consumer_circular_queue< T >::begin_
private

Beginning of the buffer.

Definition at line 173 of file producer_consumer_circular_queue.h.

◆ consumer_pos_

template<typename T >
std::atomic<storage_type*> num_collect::util::producer_consumer_circular_queue< T >::consumer_pos_
private

Position of the consumer.

Consumer will read the next object here.

Definition at line 190 of file producer_consumer_circular_queue.h.

◆ end_

template<typename T >
storage_type* num_collect::util::producer_consumer_circular_queue< T >::end_
private

Past-the-end pointer of the buffer.

Definition at line 176 of file producer_consumer_circular_queue.h.

◆ producer_pos_

template<typename T >
std::atomic<storage_type*> num_collect::util::producer_consumer_circular_queue< T >::producer_pos_
private

Position of the producer.

Producer will write the next object here.

Definition at line 183 of file producer_consumer_circular_queue.h.


The documentation for this class was generated from the following file: