A library for working with phylogenetic and population genetic data.
v0.32.0
ThreadsafeQueue< T > Class Template Reference

#include <genesis/utils/threading/threadsafe_queue.hpp>

Detailed Description

template<typename T>
class genesis::utils::ThreadsafeQueue< T >

Thread-safe queue.

This implementation is from the excellent "C++ Concurrency in Action" book by Anthony Williams, second edition, chapter 4, listing 4.5. The code is published at https://github.com/anthonywilliams/ccia_code_samples under the Boost Software License.

We simply added the Rule of Five implementations here, and renamed variables to fit with our coding standards. The rest is kept as-is.

Definition at line 89 of file threadsafe_queue.hpp.

Public Member Functions

 ThreadsafeQueue ()=default
 
 ThreadsafeQueue (ThreadsafeQueue &&other) noexcept
 
 ThreadsafeQueue (ThreadsafeQueue const &other)
 
 ~ThreadsafeQueue ()=default
 
bool empty () const
 
ThreadsafeQueueoperator= (ThreadsafeQueue &&other) noexcept
 
ThreadsafeQueueoperator= (ThreadsafeQueue const &other)
 
void push (T new_value)
 
std::shared_ptr< T > try_pop ()
 
bool try_pop (T &value)
 
std::shared_ptr< T > wait_and_pop ()
 
void wait_and_pop (T &value)
 

Constructor & Destructor Documentation

◆ ThreadsafeQueue() [1/3]

ThreadsafeQueue ( )
default

◆ ~ThreadsafeQueue()

~ThreadsafeQueue ( )
default

◆ ThreadsafeQueue() [2/3]

ThreadsafeQueue ( ThreadsafeQueue< T > const &  other)
inline

Definition at line 100 of file threadsafe_queue.hpp.

◆ ThreadsafeQueue() [3/3]

ThreadsafeQueue ( ThreadsafeQueue< T > &&  other)
inlinenoexcept

Definition at line 106 of file threadsafe_queue.hpp.

Member Function Documentation

◆ empty()

bool empty ( ) const
inline

Definition at line 193 of file threadsafe_queue.hpp.

◆ operator=() [1/2]

ThreadsafeQueue& operator= ( ThreadsafeQueue< T > &&  other)
inlinenoexcept

Definition at line 129 of file threadsafe_queue.hpp.

◆ operator=() [2/2]

ThreadsafeQueue& operator= ( ThreadsafeQueue< T > const &  other)
inline

Definition at line 112 of file threadsafe_queue.hpp.

◆ push()

void push ( new_value)
inline

Definition at line 147 of file threadsafe_queue.hpp.

◆ try_pop() [1/2]

std::shared_ptr<T> try_pop ( )
inline

Definition at line 182 of file threadsafe_queue.hpp.

◆ try_pop() [2/2]

bool try_pop ( T &  value)
inline

Definition at line 171 of file threadsafe_queue.hpp.

◆ wait_and_pop() [1/2]

std::shared_ptr<T> wait_and_pop ( )
inline

Definition at line 162 of file threadsafe_queue.hpp.

◆ wait_and_pop() [2/2]

void wait_and_pop ( T &  value)
inline

Definition at line 154 of file threadsafe_queue.hpp.


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