Caffe2 - C++ API
A deep learning, cross platform ML framework
Public Member Functions
torch::data::detail::Queue< T > Class Template Reference

A basic locked, blocking MPMC queue. More...

#include <queue.h>

Public Member Functions

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. More...
 
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. More...
 
size_t clear ()
 Empties the queue and returns the number of elements that were present at the start of the function. More...
 

Detailed Description

template<typename T>
class torch::data::detail::Queue< T >

A basic locked, blocking MPMC queue.

Every push and pop 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 to pop().

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.

Definition at line 27 of file queue.h.

Member Function Documentation

template<typename T>
size_t torch::data::detail::Queue< T >::clear ( )
inline

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.

Definition at line 68 of file queue.h.

template<typename T>
T torch::data::detail::Queue< T >::pop ( optional< std::chrono::milliseconds >  timeout = nullopt)
inline

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.

Definition at line 43 of file queue.h.

template<typename T>
void torch::data::detail::Queue< T >::push ( T  value)
inline

Pushes a new value to the back of the Queue and notifies one thread on the waiting side about this event.

Definition at line 31 of file queue.h.


The documentation for this class was generated from the following file: