VR-Forces 4.10 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties 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
DtVrfCallbackQueue Class Reference

Simple asynchronous callback queue. More...

Inheritance diagram for DtVrfCallbackQueue:
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

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

Static Public Member Functions

static void cleanup ()
 Cleans up global memory. More...
 

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. More...
 
void execute (ThreadInfo *)
 Thread main. More...
 

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 ()> DtVrfCallbackQueue::Callback
typedef tbb::mutex DtVrfCallbackQueue::Mutex
private
typedef tbb::interface5::condition_variable DtVrfCallbackQueue::Condition
private
typedef tbb::interface5::unique_lock<Mutex> DtVrfCallbackQueue::Lock
private
typedef std::multimap<double, std::ostream*, std::greater<double> > DtVrfCallbackQueue::StreamMap
private

Constructor & Destructor Documentation

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

Constructor.

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

Virtual destructor.

Member Function Documentation

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

Get label of callback queue.

static void DtVrfCallbackQueue::cleanup ( )
static

Cleans up global memory.

virtual void DtVrfCallbackQueue::setWarnTime ( double  seconds)
virtual

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

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

Print detailed info to stream.

virtual size_t DtVrfCallbackQueue::totalNumberOfCallbacks ( ) const
virtual

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

virtual unsigned DtVrfCallbackQueue::size ( ) const
virtual

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

virtual size_t DtVrfCallbackQueue::numExecuting ( ) const
virtual

Current number of callbacks executing their callbacks right now.

virtual unsigned DtVrfCallbackQueue::maxTasks ( ) const
virtual

Current max number concurrent of tasks.

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

Set max number of tasks.

Parameters
waitif true will wait for threads to exit.
void DtVrfCallbackQueue::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 DtVrfCallbackQueue::clear ( bool  wait = true)
virtual

Remove all tasks.

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

Add a job to the back of the queue.

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

Add a job to the front of the queue.

virtual void DtVrfCallbackQueue::add_back ( CallbackInterface )
virtual

Add a job to the back of the queue.

virtual void DtVrfCallbackQueue::add_front ( CallbackInterface )
virtual

Add a job to the front of the queue.

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

Add a job to the back of the queue.

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

Add a job to the front of the queue.

virtual void DtVrfCallbackQueue::add_back ( CallbackInterface )
virtual

Add a job to the back of the queue.

Caller is responsible for lifetime of callback.

virtual void DtVrfCallbackQueue::add_front ( CallbackInterface )
virtual

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

virtual bool DtVrfCallbackQueue::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 DtVrfCallbackQueue::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 DtVrfCallbackQueue::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 DtVrfCallbackQueue::execute ( ThreadInfo )
private

Thread main.

Friends And Related Function Documentation

friend struct ThreadInfo
friend

Member Data Documentation

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

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

Document ID: Generated on Tue Sep 21 17:42:52 EDT 2021 from SVN revision 234861
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)