VR-Forces Development_Version Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
List of all members | Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | Friends
DtCallbackQueue Class Reference

Simple asynchronous callback queue. More...

Inheritance diagram for DtCallbackQueue:
Inheritance graph
[legend]

Classes

class  CallbackInterface
 API for writing callbacks. More...
struct  Record
 Callback record. More...
struct  ThreadInfo

Public Types

typedef boost::function< void()> Callback

Public Member Functions

 DtCallbackQueue (const std::string &label, unsigned maxTasks)
 Constructor.
virtual ~DtCallbackQueue ()
 Virtual destructor.
virtual std::string label () const
 Get label of callback queue.
virtual void setWarnTime (double seconds)
 Queue will print warns when jobs are queued for longer than this.
virtual void setWarnTime (double seconds, std::ostream &output)
virtual void printInfo (std::ostream &, size_t width=0) const
 Print detailed info to stream.
virtual size_t totalNumberOfCallbacks () const
 Total number of callbacks added to the queue that have not finished executing.
virtual unsigned size () const
 Number of jobs currently on the queue waiting to be executed.
virtual size_t numExecuting () const
 Current number of callbacks executing their callbacks right now.
virtual unsigned maxTasks () const
 Current max number concurrent of tasks.
virtual void setMaxTasks (unsigned tasks, bool wait=true)
 Set max number of tasks.
void shutdown (bool wait=true)
 Notify all threads to shutdown.
virtual void clear (bool wait=true)
 Remove all tasks.
virtual void add_back (const Callback &, const std::string &label="")
 Add a job to the back of the queue.
virtual void add_front (const Callback &, const std::string &label="")
 Add a job to the front of the queue.
virtual void add_back (CallbackInterface *)
 Add a job to the back of the queue.
virtual void add_front (CallbackInterface *)
 Add a job to the front of the queue.
virtual void add_back (const CallbackInterface::Ptr &)
 Add a job to the back of the queue.
virtual void add_front (const CallbackInterface::Ptr &)
 Add a job to the front of the queue.
virtual void add_back (CallbackInterface &)
 Add a job to the back of the queue.
virtual void add_front (CallbackInterface &)
 Add a job to the front of the queue Caller is responsible for lifetime of callback.
virtual bool runOne (bool block=false, ThreadInfo *info=0)
 Pop and run one job from front of queue.
virtual void runAll (bool useThisThread=false)
 Will not return until the queue has empty.

Static Public Member Functions

static void cleanup ()
 Cleans up global memory.

Private Types

typedef tbb::mutex Mutex
typedef
tbb::interface5::condition_variable 
Condition
typedef
tbb::interface5::unique_lock
< Mutex
Lock
typedef std::multimap< double,
std::ostream *, std::greater
< double > > 
StreamMap

Private Member Functions

virtual bool pop (CallbackInterface::Ptr &, bool block=true, ThreadInfo *info=0)
 Pop a job from the queue, if it's empty block.
void execute (ThreadInfo *)
 Thread main.

Private Attributes

Mutex myMutex
Condition myCondition
Condition myDoneCondition
ThreadInfo::List myThreads
Record::List myCallbacks
bool myShutdownFlag
size_t myTotalNumCallbacks
tbb::atomic< size_t > myNumExecuting
DtConsoleCommandManagermyConsoleManager
std::string myLabel
StreamMap myWarnTimes

Friends

struct ThreadInfo

Detailed Description

Simple asynchronous callback queue.

Member Typedef Documentation

typedef boost::function<void ()> DtCallbackQueue::Callback
typedef tbb::mutex DtCallbackQueue::Mutex
private
typedef tbb::interface5::condition_variable DtCallbackQueue::Condition
private
typedef tbb::interface5::unique_lock<Mutex> DtCallbackQueue::Lock
private
typedef std::multimap<double, std::ostream*, std::greater<double> > DtCallbackQueue::StreamMap
private

Constructor & Destructor Documentation

DtCallbackQueue::DtCallbackQueue ( const std::string &  label,
unsigned  maxTasks 
)
explicit

Constructor.

Parameters
maxTasksmax number of threads.
virtual DtCallbackQueue::~DtCallbackQueue ( )
virtual

Virtual destructor.

Member Function Documentation

virtual std::string DtCallbackQueue::label ( ) const
virtual

Get label of callback queue.

static void DtCallbackQueue::cleanup ( )
static

Cleans up global memory.

virtual void DtCallbackQueue::setWarnTime ( double  seconds)
virtual

Queue will print warns when jobs are queued for longer than this.

virtual void DtCallbackQueue::setWarnTime ( double  seconds,
std::ostream &  output 
)
virtual
virtual void DtCallbackQueue::printInfo ( std::ostream &  ,
size_t  width = 0 
) const
virtual

Print detailed info to stream.

virtual size_t DtCallbackQueue::totalNumberOfCallbacks ( ) const
virtual

Total number of callbacks added to the queue that have not finished executing.

virtual unsigned DtCallbackQueue::size ( ) const
virtual

Number of jobs currently on the queue waiting to be executed.

virtual size_t DtCallbackQueue::numExecuting ( ) const
virtual

Current number of callbacks executing their callbacks right now.

virtual unsigned DtCallbackQueue::maxTasks ( ) const
virtual

Current max number concurrent of tasks.

virtual void DtCallbackQueue::setMaxTasks ( unsigned  tasks,
bool  wait = true 
)
virtual

Set max number of tasks.

Parameters
waitif true will wait for threads to exit.
void DtCallbackQueue::shutdown ( bool  wait = true)

Notify all threads to shutdown.

Not virtual because it is called in the destructor.

Parameters
waitIf true function will wait for all threads to end.
virtual void DtCallbackQueue::clear ( bool  wait = true)
virtual

Remove all tasks.

virtual void DtCallbackQueue::add_back ( const Callback ,
const std::string &  label = "" 
)
virtual

Add a job to the back of the queue.

virtual void DtCallbackQueue::add_front ( const Callback ,
const std::string &  label = "" 
)
virtual

Add a job to the front of the queue.

virtual void DtCallbackQueue::add_back ( CallbackInterface )
virtual

Add a job to the back of the queue.

virtual void DtCallbackQueue::add_front ( CallbackInterface )
virtual

Add a job to the front of the queue.

virtual void DtCallbackQueue::add_back ( const CallbackInterface::Ptr )
virtual

Add a job to the back of the queue.

virtual void DtCallbackQueue::add_front ( const CallbackInterface::Ptr )
virtual

Add a job to the front of the queue.

virtual void DtCallbackQueue::add_back ( CallbackInterface )
virtual

Add a job to the back of the queue.

Caller is responsible for lifetime of callback.

virtual void DtCallbackQueue::add_front ( CallbackInterface )
virtual

Add a job to the front of the queue Caller is responsible for lifetime of callback.

virtual bool DtCallbackQueue::runOne ( bool  block = false,
ThreadInfo info = 0 
)
virtual

Pop and run one job from front of queue.

Parameters
blockif true this function will wait for a job if the queue is empty.
infoThreadInfo data structure for this thread if it's managed by this object.
Returns
true if there was a job to run.
virtual void DtCallbackQueue::runAll ( bool  useThisThread = false)
virtual

Will not return until the queue has empty.

Parameters
useThisThreadif true will run callbacks with this thread, otherwise will wait. If there are no threads this parameter is ignored.
virtual bool DtCallbackQueue::pop ( CallbackInterface::Ptr ,
bool  block = true,
ThreadInfo info = 0 
)
privatevirtual

Pop a job from the queue, if it's empty block.

Parameters
blockif true this function will wait for a job if the queue is empty.
infoThreadInfo data structure for this thread if it's managed by this object.
Returns
bool false if the thread is shutting down.
void DtCallbackQueue::execute ( ThreadInfo )
private

Thread main.

Friends And Related Function Documentation

friend struct ThreadInfo
friend

Member Data Documentation

Mutex DtCallbackQueue::myMutex
mutableprivate
Condition DtCallbackQueue::myCondition
mutableprivate
Condition DtCallbackQueue::myDoneCondition
mutableprivate
ThreadInfo::List DtCallbackQueue::myThreads
private
Record::List DtCallbackQueue::myCallbacks
private
bool DtCallbackQueue::myShutdownFlag
private
size_t DtCallbackQueue::myTotalNumCallbacks
private
tbb::atomic<size_t> DtCallbackQueue::myNumExecuting
private
DtConsoleCommandManager* DtCallbackQueue::myConsoleManager
private
std::string DtCallbackQueue::myLabel
private
StreamMap DtCallbackQueue::myWarnTimes
private

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

Document ID: Generated on Tue Mar 8 22:13:38 EST 2016 from SVN revision 162938
Copyright © 2005-2015 VT MÄK. All Rights Reserved (www.mak.com)