parallel-cellular-automata
Framework for building parallel cellular automata.
Public Member Functions | List of all members
ThreadSafeQueue< T > Class Template Reference

A thread-safe wrapper around a queue. More...

#include <queues.hpp>

Public Member Functions

 ThreadSafeQueue ()
 Construct a new ThreadSafeQueue object.
 
 ThreadSafeQueue (ThreadSafeQueue const &other)
 Construct a new ThreadSafeQueue object. More...
 
void push (T elem)
 Insert an element into the queue. More...
 
bool try_pop (T &result)
 Try to pop an element from the queue. More...
 
std::shared_ptr< T > try_pop ()
 Try to pop an element from the queue. More...
 
void pop (T &result)
 Pop an element from the queue. More...
 
std::shared_ptr< T > pop ()
 Pop an element from the queue. More...
 
bool empty () const
 Check if the queue is empty. More...
 
size_t size () const
 returns the size of the queue. (The value may be outdated) More...
 

Detailed Description

template<typename T>
class ThreadSafeQueue< T >

A thread-safe wrapper around a queue.

Template Parameters
T

Constructor & Destructor Documentation

◆ ThreadSafeQueue()

template<typename T >
ThreadSafeQueue< T >::ThreadSafeQueue ( ThreadSafeQueue< T > const &  other)
inline

Construct a new ThreadSafeQueue object.

Parameters
otherqueue to copy.

Member Function Documentation

◆ empty()

template<typename T >
bool ThreadSafeQueue< T >::empty ( ) const
inline

Check if the queue is empty.

Note
The result may be outdated.
Returns
true if the queue is empty.
false if the queue is not empty.

◆ pop() [1/2]

template<typename T >
std::shared_ptr<T> ThreadSafeQueue< T >::pop ( )
inline

Pop an element from the queue.

Returns
std::shared_ptr<T> pointer containing the popped element.

◆ pop() [2/2]

template<typename T >
void ThreadSafeQueue< T >::pop ( T &  result)
inline

Pop an element from the queue.

Parameters
resultreference where to put the popped element.

◆ push()

template<typename T >
void ThreadSafeQueue< T >::push ( elem)
inline

Insert an element into the queue.

Parameters
elemelement to insert.

◆ size()

template<typename T >
size_t ThreadSafeQueue< T >::size ( ) const
inline

returns the size of the queue. (The value may be outdated)

Returns
size_t

◆ try_pop() [1/2]

template<typename T >
std::shared_ptr<T> ThreadSafeQueue< T >::try_pop ( )
inline

Try to pop an element from the queue.

Returns
std::shared_ptr<T> pointer containing the popped element or an empty pointer if the queue was empty.

◆ try_pop() [2/2]

template<typename T >
bool ThreadSafeQueue< T >::try_pop ( T &  result)
inline

Try to pop an element from the queue.

Parameters
resultreference where to put the popped element.
Returns
true if the element has been popped.
false if the queue was empty.

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