Lunchbox
1.4.0
|
A thread-safe queue with a blocking read access. More...
#include <mtQueue.h>
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. | |
T | 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. |
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.
lunchbox::MTQueue< T, S >::MTQueue | ( | size_t | maxSize = S | ) | [inline] |
lunchbox::MTQueue< T, S >::MTQueue | ( | const MTQueue< T, S > & | from | ) | [inline] |
lunchbox::MTQueue< T, S >::~MTQueue | ( | ) | [inline] |
void lunchbox::MTQueue< T, S >::clear | ( | ) | [inline] |
Reset (empty) the queue.
Definition at line 134 of file mtQueue.h.
References lunchbox::Condition::lock(), lunchbox::Condition::signal(), and lunchbox::Condition::unlock().
bool lunchbox::MTQueue< T, S >::getBack | ( | T & | result | ) | const [inline] |
result | the last value or unmodified. |
Definition at line 267 of file mtQueue.h.
References lunchbox::Condition::lock(), and lunchbox::Condition::unlock().
bool lunchbox::MTQueue< T, S >::getFront | ( | T & | result | ) | const [inline] |
result | the front value or unmodified. |
Definition at line 247 of file mtQueue.h.
References lunchbox::Condition::lock(), and lunchbox::Condition::unlock().
size_t lunchbox::MTQueue< T, S >::getMaxSize | ( | ) | const [inline] |
size_t lunchbox::MTQueue< T, S >::getSize | ( | ) | const [inline] |
bool lunchbox::MTQueue< T, S >::isEmpty | ( | ) | const [inline] |
MTQueue< T, S >& lunchbox::MTQueue< T, S >::operator= | ( | const MTQueue< T, S > & | from | ) | [inline] |
Assign the values of another queue.
Definition at line 55 of file mtQueue.h.
References lunchbox::Condition::lock(), lunchbox::Condition::signal(), and lunchbox::Condition::unlock().
const T& lunchbox::MTQueue< T, S >::operator[] | ( | const size_t | index | ) | const [inline] |
Retrieve the requested element from the queue, may block.
Definition at line 77 of file mtQueue.h.
References lunchbox::Condition::lock(), lunchbox::Condition::unlock(), and lunchbox::Condition::wait().
T lunchbox::MTQueue< T, S >::pop | ( | ) | [inline] |
Retrieve and pop the front element from the queue, may block.
Definition at line 146 of file mtQueue.h.
References lunchbox::Condition::lock(), lunchbox::Condition::signal(), lunchbox::Condition::unlock(), and lunchbox::Condition::wait().
void lunchbox::MTQueue< T, S >::push | ( | const T & | element | ) | [inline] |
Push a new element to the back of the queue.
Definition at line 282 of file mtQueue.h.
References lunchbox::Condition::lock(), lunchbox::Condition::signal(), lunchbox::Condition::unlock(), and lunchbox::Condition::wait().
void lunchbox::MTQueue< T, S >::push | ( | const std::vector< T > & | elements | ) | [inline] |
Push a vector of elements to the back of the queue.
Definition at line 293 of file mtQueue.h.
References lunchbox::Condition::lock(), lunchbox::Condition::signal(), lunchbox::Condition::unlock(), and lunchbox::Condition::wait().
void lunchbox::MTQueue< T, S >::pushFront | ( | const T & | element | ) | [inline] |
Push a new element to the front of the queue.
Definition at line 305 of file mtQueue.h.
References lunchbox::Condition::lock(), lunchbox::Condition::signal(), lunchbox::Condition::unlock(), and lunchbox::Condition::wait().
void lunchbox::MTQueue< T, S >::pushFront | ( | const std::vector< T > & | elements | ) | [inline] |
Push a vector of elements to the front of the queue.
Definition at line 316 of file mtQueue.h.
References lunchbox::Condition::lock(), lunchbox::Condition::signal(), lunchbox::Condition::unlock(), and lunchbox::Condition::wait().
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.
Definition at line 103 of file mtQueue.h.
References lunchbox::Condition::lock(), lunchbox::Condition::signal(), lunchbox::Condition::unlock(), and lunchbox::Condition::wait().
bool lunchbox::MTQueue< T, S >::timedPop | ( | const unsigned | timeout, |
T & | element | ||
) | [inline] |
Retrieve and pop the front element from the queue.
timeout | the timeout |
element | the element returned |
Exception | on timeout. |
Definition at line 169 of file mtQueue.h.
References lunchbox::Condition::lock(), lunchbox::Condition::signal(), lunchbox::Condition::timedWait(), and lunchbox::Condition::unlock().
bool lunchbox::MTQueue< T, S >::tryPop | ( | T & | result | ) | [inline] |
Retrieve and pop the front element from the queue if it is not empty.
result | the front value or unmodified. |
Definition at line 196 of file mtQueue.h.
References lunchbox::Condition::lock(), lunchbox::Condition::signal(), and lunchbox::Condition::unlock().
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.
num | the maximum number of items to retrieve |
result | the front value or unmodified. |
Definition at line 224 of file mtQueue.h.
References lunchbox::Condition::lock(), lunchbox::Condition::signal(), and lunchbox::Condition::unlock().
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.
Definition at line 122 of file mtQueue.h.
References lunchbox::Condition::lock(), lunchbox::Condition::unlock(), and lunchbox::Condition::wait().