mxnet
Public Member Functions | Static Public Member Functions | List of all members
dmlc::BlockingQueueThread< ObjectType, quit_item > Class Template Reference

Blocking queue thread class. More...

#include <thread_group.h>

Inheritance diagram for dmlc::BlockingQueueThread< ObjectType, quit_item >:
Inheritance graph
Collaboration diagram for dmlc::BlockingQueueThread< ObjectType, quit_item >:
Collaboration graph

Public Member Functions

 BlockingQueueThread (const std::string &name, dmlc::ThreadGroup *owner, std::thread *thrd=nullptr)
 Constructor. More...
 
 ~BlockingQueueThread () override
 Destructor. More...
 
void request_shutdown () override
 Signal the thread that a shutdown is desired. More...
 
void enqueue (const ObjectType &item)
 Enqueue and item. More...
 
size_t size_approx () const
 Get the approximate size of the queue. More...
 
template<typename OnItemFunction >
int run (OnItemFunction on_item_function)
 Thread's main queue processing function. More...
 
- Public Member Functions inherited from dmlc::ThreadGroup::Thread
 Thread (std::string threadName, ThreadGroup *owner, std::thread *thrd=nullptr)
 Constructor. More...
 
virtual ~Thread ()
 Destructor with cleanup. More...
 
const char * name () const
 Name of the thread. More...
 
bool is_current_thread () const
 Check if this class represents the currently running thread (self) More...
 
virtual bool is_shutdown_requested () const
 Check whether shutdown has been requested (request_shutdown() was called) More...
 
bool is_auto_remove () const
 Check whether the thread is set to auto-remove itself from the ThreadGroup owner when exiting. More...
 
void make_joinable ()
 Make the thread joinable (by removing the auto_remove flag) More...
 
bool joinable () const
 Check whether the thread is joinable. More...
 
void join ()
 Thread join. More...
 
std::thread::id get_id () const
 Get this thread's id. More...
 

Static Public Member Functions

template<typename SecondaryFunction >
static bool launch_run (std::shared_ptr< BQT > pThis, SecondaryFunction secondary_function)
 Launch to the 'run' function which will, in turn, call the class' 'run' function, passing it the given 'secondary_function' for it to call as needed. More...
 
- Static Public Member Functions inherited from dmlc::ThreadGroup::Thread
template<typename StartFunction , typename... Args>
static bool launch (std::shared_ptr< Thread > pThis, bool autoRemove, StartFunction start_function, Args...args)
 Launch the given Thread object. More...
 

Additional Inherited Members

- Public Types inherited from dmlc::ThreadGroup::Thread
using SharedPtr = std::shared_ptr< Thread >
 Shared pointer type for readability. More...
 

Detailed Description

template<typename ObjectType, ObjectType quit_item>
class dmlc::BlockingQueueThread< ObjectType, quit_item >

Blocking queue thread class.

Template Parameters
ObjectTypeObject type to queue
quit_itemObject value to signify queue shutdown (ie nullptr for pointer type is common)
Note
See gtest unit test Syc.ManagedThreadLaunchQueueThread for a usage example

Constructor & Destructor Documentation

template<typename ObjectType , ObjectType quit_item>
dmlc::BlockingQueueThread< ObjectType, quit_item >::BlockingQueueThread ( const std::string &  name,
dmlc::ThreadGroup owner,
std::thread *  thrd = nullptr 
)
inline

Constructor.

Parameters
nameName for the blockin g queue thread. Must be unique for a specific ThreadGroup
ownerThreadGroup lifecycle manafger/owner
thrdOptionally attach an existing stl thread object
template<typename ObjectType , ObjectType quit_item>
dmlc::BlockingQueueThread< ObjectType, quit_item >::~BlockingQueueThread ( )
inlineoverride

Destructor.

Member Function Documentation

template<typename ObjectType , ObjectType quit_item>
void dmlc::BlockingQueueThread< ObjectType, quit_item >::enqueue ( const ObjectType &  item)
inline

Enqueue and item.

Parameters
itemThe item to enqueue
template<typename ObjectType , ObjectType quit_item>
template<typename SecondaryFunction >
static bool dmlc::BlockingQueueThread< ObjectType, quit_item >::launch_run ( std::shared_ptr< BQT pThis,
SecondaryFunction  secondary_function 
)
inlinestatic

Launch to the 'run' function which will, in turn, call the class' 'run' function, passing it the given 'secondary_function' for it to call as needed.

Template Parameters
SecondaryFunctionType of the secondary function for 'run' override to call as needed
Parameters
pThisPointer to the managed thread to launch
secondary_functionsecondary function for 'run' override to call as needed
Returns
true if thread is launched successfully and added to the ThreadGroup
template<typename ObjectType , ObjectType quit_item>
void dmlc::BlockingQueueThread< ObjectType, quit_item >::request_shutdown ( )
inlineoverridevirtual

Signal the thread that a shutdown is desired.

Note
Since consumer doesn't necessarily get items in order, we must wait for the queue to empty. This is generally a shutdown procedure and should not be called from a performance-sensitive area

Reimplemented from dmlc::ThreadGroup::Thread.

template<typename ObjectType , ObjectType quit_item>
template<typename OnItemFunction >
int dmlc::BlockingQueueThread< ObjectType, quit_item >::run ( OnItemFunction  on_item_function)
inline

Thread's main queue processing function.

Template Parameters
OnItemFunctionFunction type to call when an item is dequeued
Parameters
on_item_functionFunction to call when an item is dequeued
Returns
0 if completed through a quit_item, nonzero if on_item_function requested an exit
template<typename ObjectType , ObjectType quit_item>
size_t dmlc::BlockingQueueThread< ObjectType, quit_item >::size_approx ( ) const
inline

Get the approximate size of the queue.

Returns
The approximate size of the queue

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