Instrument Neutral Distributed Interface INDI  1.9.5
Public Member Functions | Protected Attributes | List of all members
UniqueQueue< T > Class Template Reference

The UniqueQueue class is a thread-safe FIFO container adapter. More...

#include <uniquequeue.h>

Public Member Functions

void push (T &&data)
 Move data to queue. More...
 
bool pop (T &dest)
 Pop data from queue. More...
 
bool pop (T &dest, uint32_t msecs)
 Pop data from queue. More...
 
void waitForEmpty () const
 Wait for an empty queue. More...
 
bool waitForEmpty (uint32_t msecs) const
 Wait for an empty queue. More...
 
void clear ()
 Clear queue. More...
 
void abort ()
 Clear queue and exit pop methods with false return. More...
 
size_t size () const
 Return the number of items in the queue. More...
 

Protected Attributes

std::queue< T > queue
 
std::mutex mutex
 
std::condition_variable decrease
 
std::condition_variable increase
 

Detailed Description

template<typename T>
class UniqueQueue< T >

The UniqueQueue class is a thread-safe FIFO container adapter.

Data is move to the queue, which ensures high efficiency when collecting data, e.g. for processing. This class ensures that threads are wake up waiting for data. It also provides a convenient "abort" method to wake up those waiting if there is no more data to process. Don't use it for large class/arrays (sizeof T). Provide an interface that allows data to be swapped/moved as pointers, like std::vector or simple pointers.

Definition at line 35 of file uniquequeue.h.

Member Function Documentation

◆ abort()

template<typename T >
void UniqueQueue< T >::abort
inline

Clear queue and exit pop methods with false return.

Definition at line 168 of file uniquequeue.h.

◆ clear()

template<typename T >
void UniqueQueue< T >::clear
inline

Clear queue.

Definition at line 145 of file uniquequeue.h.

◆ pop() [1/2]

template<typename T >
bool UniqueQueue< T >::pop ( T &  dest)
inline

Pop data from queue.

Parameters
destthe data will be swapped and destroyed
Returns
returns false if the abort function was called while waiting for data

Definition at line 105 of file uniquequeue.h.

◆ pop() [2/2]

template<typename T >
bool UniqueQueue< T >::pop ( T &  dest,
uint32_t  msecs 
)
inline

Pop data from queue.

Parameters
destthe data will be swapped and destroyed
msecstimeout in milliseconds
Returns
returns false if timeout or the abort function was called while waiting for data

Definition at line 121 of file uniquequeue.h.

◆ push()

template<typename T >
void UniqueQueue< T >::push ( T &&  data)
inline

Move data to queue.

Parameters
datathe data will be moved using std::move

Definition at line 97 of file uniquequeue.h.

◆ size()

template<typename T >
size_t UniqueQueue< T >::size
inline

Return the number of items in the queue.

Returns
count of elements

Definition at line 138 of file uniquequeue.h.

◆ waitForEmpty() [1/2]

template<typename T >
void UniqueQueue< T >::waitForEmpty
inline

Wait for an empty queue.

Definition at line 154 of file uniquequeue.h.

◆ waitForEmpty() [2/2]

template<typename T >
bool UniqueQueue< T >::waitForEmpty ( uint32_t  msecs) const
inline

Wait for an empty queue.

Parameters
msecstimeout in milliseconds
Returns
returns false if timeout

Definition at line 161 of file uniquequeue.h.

Member Data Documentation

◆ decrease

template<typename T >
std::condition_variable UniqueQueue< T >::decrease
mutableprotected

Definition at line 91 of file uniquequeue.h.

◆ increase

template<typename T >
std::condition_variable UniqueQueue< T >::increase
mutableprotected

Definition at line 92 of file uniquequeue.h.

◆ mutex

template<typename T >
std::mutex UniqueQueue< T >::mutex
mutableprotected

Definition at line 89 of file uniquequeue.h.

◆ queue

template<typename T >
std::queue<T> UniqueQueue< T >::queue
protected

Definition at line 88 of file uniquequeue.h.


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