Lunchbox  1.6.0
Public Member Functions
lunchbox::MTQueue< T, S > Class Template Reference

A thread-safe queue with a blocking read access. More...

#include <mtQueue.h>

List of all members.

Public Member Functions

 MTQueue (size_t maxSize=S)
 Construct a new queue.
 MTQueue (const MTQueue< T, S > &from)
 Construct a copy of a queue.
 ~MTQueue ()
 Destruct this Queue.
MTQueue< T, S > & operator= (const MTQueue< T, S > &from)
 Assign the values of another queue.
const T & operator[] (const size_t index) const
 Retrieve the requested element from the queue, may block.
bool isEmpty () const
size_t getSize () const
void setMaxSize (const size_t maxSize)
 Set the new maximum size of the queue.
size_t getMaxSize () const
size_t waitSize (const size_t minSize) const
 Wait for the size to be at least the number of given elements.
void clear ()
 Reset (empty) the queue.
pop ()
 Retrieve and pop the front element from the queue, may block.
bool timedPop (const unsigned timeout, T &element)
 Retrieve and pop the front element from the queue.
bool tryPop (T &result)
 Retrieve and pop the front element from the queue if it is not empty.
void tryPop (const size_t num, std::vector< T > &result)
 Try to retrieve a number of items for the front of the queue.
bool getFront (T &result) const
bool getBack (T &result) const
void push (const T &element)
 Push a new element to the back of the queue.
void push (const std::vector< T > &elements)
 Push a vector of elements to the back of the queue.
void pushFront (const T &element)
 Push a new element to the front of the queue.
void pushFront (const std::vector< T > &elements)
 Push a vector of elements to the front of the queue.

Detailed Description

template<typename T, size_t S = ULONG_MAX>
class lunchbox::MTQueue< T, S >

A thread-safe queue with a blocking read access.

Typically used to communicate between two execution threads.

S is deprecated, and defines the initial maximum capacity of the Queue<T>. When the capacity is reached, pushing new values blocks until items have been consumed.

Definition at line 41 of file mtQueue.h.


Constructor & Destructor Documentation

template<typename T, size_t S = ULONG_MAX>
lunchbox::MTQueue< T, S >::MTQueue ( size_t  maxSize = S) [inline]

Construct a new queue.

Version:
1.0

Definition at line 47 of file mtQueue.h.

template<typename T, size_t S = ULONG_MAX>
lunchbox::MTQueue< T, S >::MTQueue ( const MTQueue< T, S > &  from) [inline]

Construct a copy of a queue.

Version:
1.0

Definition at line 50 of file mtQueue.h.

template<typename T, size_t S = ULONG_MAX>
lunchbox::MTQueue< T, S >::~MTQueue ( ) [inline]

Destruct this Queue.

Version:
1.0

Definition at line 53 of file mtQueue.h.


Member Function Documentation

template<typename T, size_t S = ULONG_MAX>
void lunchbox::MTQueue< T, S >::clear ( ) [inline]

Reset (empty) the queue.

Version:
1.0

Definition at line 135 of file mtQueue.h.

References lunchbox::Condition::lock(), lunchbox::Condition::signal(), and lunchbox::Condition::unlock().

+ Here is the call graph for this function:

template<typename T, size_t S = ULONG_MAX>
bool lunchbox::MTQueue< T, S >::getBack ( T &  result) const [inline]
Parameters:
resultthe last value or unmodified.
Returns:
true if an element was placed in result, false if the queue is empty.
Version:
1.0

Definition at line 268 of file mtQueue.h.

References lunchbox::Condition::lock(), and lunchbox::Condition::unlock().

+ Here is the call graph for this function:

template<typename T, size_t S = ULONG_MAX>
bool lunchbox::MTQueue< T, S >::getFront ( T &  result) const [inline]
Parameters:
resultthe front value or unmodified.
Returns:
true if an element was placed in result, false if the queue is empty.
Version:
1.0

Definition at line 248 of file mtQueue.h.

References lunchbox::Condition::lock(), and lunchbox::Condition::unlock().

+ Here is the call graph for this function:

template<typename T, size_t S = ULONG_MAX>
size_t lunchbox::MTQueue< T, S >::getMaxSize ( ) const [inline]
Returns:
the current maximum size of the queue.
Version:
1.3.2

Definition at line 115 of file mtQueue.h.

template<typename T, size_t S = ULONG_MAX>
size_t lunchbox::MTQueue< T, S >::getSize ( ) const [inline]
Returns:
the number of items currently in the queue.
Version:
1.0

Definition at line 94 of file mtQueue.h.

template<typename T, size_t S = ULONG_MAX>
bool lunchbox::MTQueue< T, S >::isEmpty ( ) const [inline]
Returns:
true if the queue is empty, false otherwise.
Version:
1.0

Definition at line 91 of file mtQueue.h.

template<typename T, size_t S = ULONG_MAX>
MTQueue< T, S >& lunchbox::MTQueue< T, S >::operator= ( const MTQueue< T, S > &  from) [inline]

Assign the values of another queue.

Version:
1.0

Definition at line 56 of file mtQueue.h.

References lunchbox::Condition::lock(), lunchbox::Condition::signal(), and lunchbox::Condition::unlock().

+ Here is the call graph for this function:

template<typename T, size_t S = ULONG_MAX>
const T& lunchbox::MTQueue< T, S >::operator[] ( const size_t  index) const [inline]

Retrieve the requested element from the queue, may block.

Version:
1.3.2

Definition at line 78 of file mtQueue.h.

References lunchbox::Condition::lock(), lunchbox::Condition::unlock(), and lunchbox::Condition::wait().

+ Here is the call graph for this function:

template<typename T, size_t S = ULONG_MAX>
T lunchbox::MTQueue< T, S >::pop ( ) [inline]

Retrieve and pop the front element from the queue, may block.

Version:
1.0

Definition at line 147 of file mtQueue.h.

References lunchbox::Condition::lock(), lunchbox::Condition::signal(), lunchbox::Condition::unlock(), and lunchbox::Condition::wait().

+ Here is the call graph for this function:

template<typename T, size_t S = ULONG_MAX>
void lunchbox::MTQueue< T, S >::push ( const T &  element) [inline]

Push a new element to the back of the queue.

Version:
1.0

Definition at line 283 of file mtQueue.h.

References lunchbox::Condition::lock(), lunchbox::Condition::signal(), lunchbox::Condition::unlock(), and lunchbox::Condition::wait().

+ Here is the call graph for this function:

template<typename T, size_t S = ULONG_MAX>
void lunchbox::MTQueue< T, S >::push ( const std::vector< T > &  elements) [inline]

Push a vector of elements to the back of the queue.

Version:
1.0

Definition at line 294 of file mtQueue.h.

References lunchbox::Condition::lock(), lunchbox::Condition::signal(), lunchbox::Condition::unlock(), and lunchbox::Condition::wait().

+ Here is the call graph for this function:

template<typename T, size_t S = ULONG_MAX>
void lunchbox::MTQueue< T, S >::pushFront ( const T &  element) [inline]

Push a new element to the front of the queue.

Version:
1.0

Definition at line 306 of file mtQueue.h.

References lunchbox::Condition::lock(), lunchbox::Condition::signal(), lunchbox::Condition::unlock(), and lunchbox::Condition::wait().

+ Here is the call graph for this function:

template<typename T, size_t S = ULONG_MAX>
void lunchbox::MTQueue< T, S >::pushFront ( const std::vector< T > &  elements) [inline]

Push a vector of elements to the front of the queue.

Version:
1.0

Definition at line 317 of file mtQueue.h.

References lunchbox::Condition::lock(), lunchbox::Condition::signal(), lunchbox::Condition::unlock(), and lunchbox::Condition::wait().

+ Here is the call graph for this function:

template<typename T, size_t S = ULONG_MAX>
void lunchbox::MTQueue< T, S >::setMaxSize ( const size_t  maxSize) [inline]

Set the new maximum size of the queue.

If the new maximum size is less the current size of the queue, this call will block until the queue reaches the new maximum size.

Version:
1.3.2

Definition at line 104 of file mtQueue.h.

References lunchbox::Condition::lock(), lunchbox::Condition::signal(), lunchbox::Condition::unlock(), and lunchbox::Condition::wait().

+ Here is the call graph for this function:

template<typename T, size_t S = ULONG_MAX>
bool lunchbox::MTQueue< T, S >::timedPop ( const unsigned  timeout,
T &  element 
) [inline]

Retrieve and pop the front element from the queue.

Parameters:
timeoutthe timeout
elementthe element returned
Returns:
true if an element was popped
Exceptions:
Exceptionon timeout.
Version:
1.1

Definition at line 170 of file mtQueue.h.

References lunchbox::Condition::lock(), lunchbox::Condition::signal(), lunchbox::Condition::timedWait(), and lunchbox::Condition::unlock().

+ Here is the call graph for this function:

template<typename T, size_t S = ULONG_MAX>
bool lunchbox::MTQueue< T, S >::tryPop ( T &  result) [inline]

Retrieve and pop the front element from the queue if it is not empty.

Parameters:
resultthe front value or unmodified.
Returns:
true if an element was placed in result, false if the queue is empty.
Version:
1.0

Definition at line 197 of file mtQueue.h.

References lunchbox::Condition::lock(), lunchbox::Condition::signal(), and lunchbox::Condition::unlock().

+ Here is the call graph for this function:

template<typename T, size_t S = ULONG_MAX>
void lunchbox::MTQueue< T, S >::tryPop ( const size_t  num,
std::vector< T > &  result 
) [inline]

Try to retrieve a number of items for the front of the queue.

Between zero and the given number of items are appended to the vector.

Parameters:
numthe maximum number of items to retrieve
resultthe front value or unmodified.
Returns:
true if an element was placed in result, false if the queue is empty.
Version:
1.1.6

Definition at line 225 of file mtQueue.h.

References lunchbox::Condition::lock(), lunchbox::Condition::signal(), and lunchbox::Condition::unlock().

+ Here is the call graph for this function:

template<typename T, size_t S = ULONG_MAX>
size_t lunchbox::MTQueue< T, S >::waitSize ( const size_t  minSize) const [inline]

Wait for the size to be at least the number of given elements.

Returns:
the current size when the condition was fulfilled.
Version:
1.0

Definition at line 123 of file mtQueue.h.

References lunchbox::Condition::lock(), lunchbox::Condition::unlock(), and lunchbox::Condition::wait().

+ Here is the call graph for this function:


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