67 _queue.push(std::move(
val));
77 template <
typename...
Args>
80 _queue.emplace(std::forward<Args>(
args)...);
107 [
this] {
return !_queue.empty(); },
timeoutMs);
109 T ret = std::move(_queue.front());
111 if(_queue.empty()) _cv.
wakeAll();
122 if(_queue.empty())
return false;
123 val = std::move(_queue.front());
125 if(_queue.empty()) _cv.
wakeAll();
140 [
this] {
return !_queue.empty(); },
timeoutMs);
142 T ret = _queue.front();
153 if(_queue.empty())
return false;
154 val = _queue.front();
173 return _cv.
wait(_mutex,
174 [
this] {
return _queue.empty(); },
timeoutMs);
183 return _queue.empty();
192 return _queue.size();
201 std::swap(_queue,
empty);
206 mutable Mutex _mutex;
208 std::queue<T> _queue;
Lightweight error code wrapper for the promeki library.
Definition error.h:39
@ Ok
No error.
Definition error.h:51
Dynamic array container wrapping std::vector.
Definition list.h:40
RAII scoped locker for Mutex.
Definition mutex.h:41
Mutual exclusion lock wrapping std::mutex.
Definition mutex.h:33
Thread-safe FIFO queue.
Definition queue.h:45
std::pair< T, Error > pop(unsigned int timeoutMs=0)
Removes and returns the front element, blocking until one is available or the timeout expires.
Definition queue.h:104
bool isEmpty() const
Returns true if the queue has no elements.
Definition queue.h:181
void push(T &&val)
Moves val onto the back of the queue.
Definition queue.h:65
size_t size() const
Returns the number of elements currently in the queue.
Definition queue.h:190
void emplace(Args &&... args)
Constructs an element in-place at the back of the queue.
Definition queue.h:78
bool popOrFail(T &val)
Tries to pop the front element without blocking.
Definition queue.h:120
Error waitForEmpty(unsigned int timeoutMs=0)
Blocks until the queue is empty.
Definition queue.h:171
void push(const T &val)
Pushes a copy of val onto the back of the queue.
Definition queue.h:54
void clear()
Removes all elements from the queue.
Definition queue.h:198
void push(const List< T > &list)
Pushes every element in list onto the back of the queue.
Definition queue.h:89
std::pair< T, Error > peek(unsigned int timeoutMs=0)
Returns a copy of the front element without removing it, blocking until one is available or the timeo...
Definition queue.h:137
bool peekOrFail(T &val)
Tries to copy the front element without blocking or removing it.
Definition queue.h:151
Condition variable wrapping std::condition_variable.
Definition waitcondition.h:26
void wakeAll()
Wakes all waiting threads.
Definition waitcondition.h:99
Error wait(Mutex &mutex, unsigned int timeoutMs=0)
Waits until woken or the timeout expires.
Definition waitcondition.h:50
void wakeOne()
Wakes one waiting thread.
Definition waitcondition.h:94
#define PROMEKI_NAMESPACE_BEGIN
Starts a promeki namespace block.
Definition namespace.h:14
#define PROMEKI_NAMESPACE_END
Ends a promeki namespace block.
Definition namespace.h:19