Template Class Queue¶
Defined in File queue.h
Page Contents
Class Documentation¶
-
template<typename T>
class Queue¶ A basic locked, blocking MPMC queue.
Every
push
andpop
is guarded by a mutex. A condition variable is used to communicate insertion of new elements, such that waiting threads will be woken up if they are currently waiting inside a call topop()
.Note that this data structure is written specifically for use with the
DataLoader
. Its behavior is tailored to this use case and may not be applicable to more general uses.Public Functions
-
inline void push(T value)¶
Pushes a new value to the back of the
Queue
and notifies one thread on the waiting side about this event.
-
inline T pop(optional<std::chrono::milliseconds> timeout = nullopt)¶
Blocks until at least one element is ready to be popped from the front of the queue.
An optional
timeout
in seconds can be used to limit the time spent waiting for an element. If the wait times out, an exception is raised.
-
inline size_t clear()¶
Empties the queue and returns the number of elements that were present at the start of the function.
No threads are notified about this event as it is assumed to be used to drain the queue during shutdown of a
DataLoader
.
-
inline void push(T value)¶