19 #ifndef LUNCHBOX_MTQUEUE_H 20 #define LUNCHBOX_MTQUEUE_H 22 #include <lunchbox/debug.h> 25 #include <condition_variable> 44 template <
typename T,
size_t S = ULONG_MAX>
54 explicit MTQueue(
const size_t maxSize = S)
73 bool isEmpty()
const {
return _queue.empty(); }
75 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);
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(); }
213 std::deque<T> _queue;
214 mutable std::mutex _mutex;
215 mutable std::condition_variable _condition;
220 #include "mtQueue.ipp" 222 #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.
Abstraction layer and common utilities for multi-threaded programming.
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.