iLab Neuromorphic Robotics Toolkit  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
nrt::ConcurrentQueue< T > Class Template Reference

#include <nrt/Core/Design/ConcurrentQueue.H>

template<class T>
class nrt::ConcurrentQueue< T >

A thread safe queue with blocking and waiting.

This class provides a thread safe queue that blocks and waits while pushing and popping data.

Based off of an implementation in C++ Concurrency in Action: Practical Multithreading by Anthony Williams

Definition at line 53 of file ConcurrentQueue.H.

Public Member Functions

 ConcurrentQueue ()
 Constructs an empty queue.
 
 ConcurrentQueue (ConcurrentQueue const &other)=delete
 Queues cannot be copy constructed.
 
ConcurrentQueueoperator= (ConcurrentQueue const &other)=delete
 Queues cannot be copy assigned.
 
 ~ConcurrentQueue ()
 Destructor.
 
std::shared_ptr< T > tryPop ()
 Pops a value off of the queue if available, otherwise returns a nullptr.
 
bool tryPop (T &value)
 Pops a value off of the queue if available, returning true if successful.
 
std::shared_ptr< T > waitAndPop ()
 Pops a value off of the queue, waiting until a value is available.
 
void waitAndPop (T &value)
 Pops a value off of the queue, waiting until a value is available.
 
void push (T newValue)
 Pushes a new value onto the queue.
 
bool empty ()
 Checks if the queue is empty.
 
void clear ()
 Empties the queue.
 

Protected Member Functions

Node * getTail ()
 Gets the current tail node.
 
std::unique_ptr< Node > popHead ()
 Pops the head node.
 
std::unique_lock< std::mutex > waitForData ()
 Creates a lock used to sleep until data is available.
 
std::unique_ptr< Node > waitPopHead ()
 Pops the head node, sleeping until data is available.
 
std::unique_ptr< Node > waitPopHead (T &value)
 Pops the head node, sleeping until data is available.
 
std::unique_ptr< Node > tryPopHead ()
 Pops the head node if it exists, otherwise returns nullptr.
 
std::unique_ptr< Node > tryPopHead (T &value)
 Pops the head node if it exists, otherwise returns nullptr.
 

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