19 #ifndef LUNCHBOX_MTQUEUE_H
20 #define LUNCHBOX_MTQUEUE_H
22 #include <lunchbox/condition.h>
23 #include <lunchbox/debug.h>
43 template<
typename T,
size_t S = ULONG_MAX >
class MTQueue
52 explicit MTQueue(
const size_t maxSize = S ) : _maxSize( maxSize ) {}
67 const T&
operator[](
const size_t index )
const;
70 bool isEmpty()
const {
return _queue.empty(); }
73 size_t getSize()
const {
return _queue.size(); }
94 size_t waitSize(
const size_t minSize )
const;
113 bool timedPop(
const unsigned timeout, T& element );
134 const size_t minimum = 1,
135 const size_t maximum = S );
158 void tryPop(
const size_t num, std::vector< T >& result );
189 bool getBack( T& result )
const;
192 void push(
const T& element );
195 void push(
const std::vector< T >& elements );
201 void pushFront(
const std::vector< T >& elements );
205 void push_back(
const T& element ) {
push( element ); }
206 bool empty()
const {
return isEmpty(); }
210 std::deque< T > _queue;
211 mutable Condition _cond;
216 #include "mtQueue.ipp"
218 #endif //LUNCHBOX_MTQUEUE_H
std::vector< T > timedPopRange(const unsigned timeout, const size_t minimum=1, const size_t maximum=S)
Retrieve a number of items from the front of the queue.
bool tryPop(T &result)
Retrieve and pop the front element from the queue if it is not empty.
MTQueue< T, S > & operator=(const MTQueue< T, S > &from)
Assign the values of another queue.
void pushFront(const T &element)
Push a new element to the front of the queue.
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.
A thread-safe queue with a blocking read access.
const T & operator[](const size_t index) const
Retrieve the requested element from the queue, may block.
~MTQueue()
Destruct this Queue.
bool getFront(T &result) const
bool popBarrier(T &result, Group &barrier)
Retrieve the front element, or abort if the barrier is reached.
void setMaxSize(const size_t maxSize)
Set the new maximum size of the queue.
bool getBack(T &result) const
bool timedPop(const unsigned timeout, T &element)
Retrieve and pop the front element from the queue.
MTQueue(const MTQueue< T, S > &from)
Construct a copy of a queue.
Group descriptor for popBarrier().
T pop()
Retrieve and pop the front element from the queue, may block.
MTQueue(const size_t maxSize=S)
Construct a new queue.
size_t getMaxSize() const
void push(const T &element)
Push a new element to the back of the queue.