VR-Forces 4.3 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 | Private Types | Private Member Functions | Private Attributes
DtParallelTickManager Class Reference

Enables parallelism in the main thread. More...

Inheritance diagram for DtParallelTickManager:
Inheritance graph
[legend]

Classes

class  CallbackInterface
 Interface for defining callbacks. More...
class  ParallelScopeGuard
 Scope guard used to mark a section of code which can be executed in parallel. More...
class  SerialCallbackInterface
 Interface for defining serial callbacks. More...
class  SerialScopeGuard
 Scope guard used to mark a section of code which must be executed in serial. More...

Public Types

typedef boost::unordered_map
< std::string, bool
EnabledMap

Public Member Functions

 DtParallelTickManager (DtVrfSimOptionsInterface *options)
virtual ~DtParallelTickManager ()
virtual void setCallbackQueue (DtCallbackQueue *)
 Takes ownership.
virtual DtCallbackQueuequeue () const
 Access the callback queue object.
virtual bool enabled (const std::string &, bool def) const
 Simple mechanism for controlling multiple parallel sections.
virtual bool executeCommand (const std::string &, bool on)
 Execute a console command.
virtual void printInfo (std::ostream &) const
 Print information about current state.
virtual void flushQueue (bool useThisThread)
 Wait for all queued tasks to complete This function is called when you have added a bunch of tasks to the queue and need to make sure they are finished before proceeding.
virtual void flushQueue ()
 Wait for all queued tasks to complete This function is called when you have added a bunch of tasks to the queue and need to make sure they are finished before proceeding.
virtual bool mainThreadWait () const
 Accessor/mutator for main thread participation in running callbacks.
virtual void setMainThreadWait (bool)
 Accessor/mutator for main thread participation in running callbacks.
virtual bool active () const
 Accessorm/mutator for the entire parallel mechanism.
virtual void setActive (bool)
 Accessorm/mutator for the entire parallel mechanism.
virtual void addCallback (CallbackInterface *, bool runNow=false)
 Add callbacks to the queue.
virtual void addCallback (CallbackInterface &, bool runNow=false)
 Add callbacks to the queue.
virtual void addCallback (SerialCallbackInterface *, bool runNow=false)
 Add callbacks to the queue.
virtual void addCallback (SerialCallbackInterface &, bool runNow=false)
 Add callbacks to the queue.
virtual void addCallback (CallbackInterface *, const std::string &tag, bool def=true)
 Add callbacks to the queue.
virtual void addCallback (CallbackInterface &, const std::string &tag, bool def=true)
 Add callbacks to the queue.
virtual void addCallback (SerialCallbackInterface *, const std::string &tag, bool def=true)
 Add callbacks to the queue.
virtual void addCallback (SerialCallbackInterface &, const std::string &tag, bool def=true)
 Add callbacks to the queue.
void addCallback (CallbackInterface *, const char *tag, bool def=true)
 Add callbacks to the queue.
void addCallback (CallbackInterface &, const char *tag, bool def=true)
 Add callbacks to the queue.
void addCallback (SerialCallbackInterface *, const char *tag, bool def=true)
 Add callbacks to the queue.
void addCallback (SerialCallbackInterface &, const char *tag, bool def=true)
 Add callbacks to the queue.
template<typename Container >
void addCallbacks (Container &cont, bool runNow=false)
 Add callbacks to the queue.
template<typename Container >
void addCallbacks (Container &cont, const std::string &tag, bool def=true)
 Add callbacks to the queue.
template<typename Container >
void addCallbacks (Container &cont, const char *tag, bool def=true)
 Add callbacks to the queue.

Private Types

typedef tbb::mutex Mutex
typedef
tbb::interface5::condition_variable 
Condition
typedef
tbb::interface5::unique_lock
< Mutex
Lock

Private Member Functions

virtual void createCallbackQueue (bool force=false)
 Create the callback queue.
virtual void lock ()
 Manipulate global mutex.
virtual void unlock ()
 Manipulate global mutex.
virtual void readLock ()
 Manipulate global mutex.
virtual void readUnlock ()
 Manipulate global mutex.
virtual bool upgradeToWriter ()
 Manipulate global mutex.
virtual void downgradeToReader ()
 Manipulate global mutex.

Private Attributes

Mutex myMutex
Condition myCondition
size_t myReaderCount
DtVrfSimOptionsInterfacemyOptions
DtCallbackQueuemyCallbackQueue
EnabledMap myEnabledMap
bool myWaitFlag
DtSubCommandManagermyCommandManager
DtConsoleCommandOwnermyCommandOwner

Detailed Description

Enables parallelism in the main thread.

This class wraps a mutex and a callback queue thread pool which are used to execute multiple functions in parallel in the sim main thread. The mutex protects the entire global state of VR-Forces.

There are two ways to execute a callback, normal (parallel) or serial. The normal method just executes the callback with no synchronization. If the callback needs to access any of the global VR-Forces state then it must use create a SerialScopeGuard around that section (just like a mutex scope lock). This will lock the global mutex and prevent any other threads from access the global state. The serial method locks the global mutex when the callback is called This means that all other threads accessing the global state will have to wait. A serial executed callback can use ParallelScopeGuard to unlock the global mutex around a section which does not access any global state.

By default DtVrfObjects are ticked in serial since they all access the global state. Individual actuators that have safe sections (like terrain intersections or feature queries) can then be modified as needed by inserting ParallelScopeGuards.

Member Typedef Documentation

typedef boost::unordered_map<std::string, bool> DtParallelTickManager::EnabledMap
typedef tbb::mutex DtParallelTickManager::Mutex
private
typedef tbb::interface5::condition_variable DtParallelTickManager::Condition
private
typedef tbb::interface5::unique_lock<Mutex> DtParallelTickManager::Lock
private

Constructor & Destructor Documentation

DtParallelTickManager::DtParallelTickManager ( DtVrfSimOptionsInterface options)
explicit
virtual DtParallelTickManager::~DtParallelTickManager ( )
virtual

Member Function Documentation

virtual void DtParallelTickManager::setCallbackQueue ( DtCallbackQueue )
virtual

Takes ownership.

virtual DtCallbackQueue* DtParallelTickManager::queue ( ) const
virtual

Access the callback queue object.

virtual void DtParallelTickManager::flushQueue ( bool  useThisThread)
virtual

Wait for all queued tasks to complete This function is called when you have added a bunch of tasks to the queue and need to make sure they are finished before proceeding.

Whether the calling thread waits or participates in calling the callbacks is controlled by the useThisThread parameter or DtVrfSimOptionsInterface::flushCallbackQueueInMainThread if not supplied.

virtual void DtParallelTickManager::flushQueue ( )
virtual

Wait for all queued tasks to complete This function is called when you have added a bunch of tasks to the queue and need to make sure they are finished before proceeding.

Whether the calling thread waits or participates in calling the callbacks is controlled by the useThisThread parameter or DtVrfSimOptionsInterface::flushCallbackQueueInMainThread if not supplied.

virtual bool DtParallelTickManager::mainThreadWait ( ) const
virtual

Accessor/mutator for main thread participation in running callbacks.

virtual void DtParallelTickManager::setMainThreadWait ( bool  )
virtual

Accessor/mutator for main thread participation in running callbacks.

virtual bool DtParallelTickManager::active ( ) const
virtual

Accessorm/mutator for the entire parallel mechanism.

Disabling will delete the queue and execute callbacks in the calling thread.

virtual void DtParallelTickManager::setActive ( bool  )
virtual

Accessorm/mutator for the entire parallel mechanism.

Disabling will delete the queue and execute callbacks in the calling thread.

virtual bool DtParallelTickManager::enabled ( const std::string &  ,
bool  def 
) const
virtual

Simple mechanism for controlling multiple parallel sections.

This class is designed to be used by multiple sections of code to execute different sets of parallel callbacks. This function allows each of those sections to be named and then have their options controlled individually by this class. If you supply a tag in any of the add callback functions a record will be made of that that tag by this function.

Parameters
defDefault value to record if it's a new tag.

Referenced by addCallbacks().

virtual bool DtParallelTickManager::executeCommand ( const std::string &  ,
bool  on 
)
virtual

Execute a console command.

virtual void DtParallelTickManager::printInfo ( std::ostream &  ) const
virtual

Print information about current state.

virtual void DtParallelTickManager::addCallback ( CallbackInterface ,
bool  runNow = false 
)
virtual

Add callbacks to the queue.

The pointer versions take ownership of their callbacks. The reference versions do not and require the caller to keep them alive. The container versions add an STL-like container of callbacks.

Parameters
runNowExecute the callback right now instead of adding it the queue.
tagSee enabled().
defDefault value for enabled().

Referenced by addCallbacks().

virtual void DtParallelTickManager::addCallback ( CallbackInterface ,
bool  runNow = false 
)
virtual

Add callbacks to the queue.

The pointer versions take ownership of their callbacks. The reference versions do not and require the caller to keep them alive. The container versions add an STL-like container of callbacks.

Parameters
runNowExecute the callback right now instead of adding it the queue.
tagSee enabled().
defDefault value for enabled().
virtual void DtParallelTickManager::addCallback ( SerialCallbackInterface ,
bool  runNow = false 
)
virtual

Add callbacks to the queue.

The pointer versions take ownership of their callbacks. The reference versions do not and require the caller to keep them alive. The container versions add an STL-like container of callbacks.

Parameters
runNowExecute the callback right now instead of adding it the queue.
tagSee enabled().
defDefault value for enabled().
virtual void DtParallelTickManager::addCallback ( SerialCallbackInterface ,
bool  runNow = false 
)
virtual

Add callbacks to the queue.

The pointer versions take ownership of their callbacks. The reference versions do not and require the caller to keep them alive. The container versions add an STL-like container of callbacks.

Parameters
runNowExecute the callback right now instead of adding it the queue.
tagSee enabled().
defDefault value for enabled().
virtual void DtParallelTickManager::addCallback ( CallbackInterface ,
const std::string &  tag,
bool  def = true 
)
virtual

Add callbacks to the queue.

The pointer versions take ownership of their callbacks. The reference versions do not and require the caller to keep them alive. The container versions add an STL-like container of callbacks.

Parameters
runNowExecute the callback right now instead of adding it the queue.
tagSee enabled().
defDefault value for enabled().
virtual void DtParallelTickManager::addCallback ( CallbackInterface ,
const std::string &  tag,
bool  def = true 
)
virtual

Add callbacks to the queue.

The pointer versions take ownership of their callbacks. The reference versions do not and require the caller to keep them alive. The container versions add an STL-like container of callbacks.

Parameters
runNowExecute the callback right now instead of adding it the queue.
tagSee enabled().
defDefault value for enabled().
virtual void DtParallelTickManager::addCallback ( SerialCallbackInterface ,
const std::string &  tag,
bool  def = true 
)
virtual

Add callbacks to the queue.

The pointer versions take ownership of their callbacks. The reference versions do not and require the caller to keep them alive. The container versions add an STL-like container of callbacks.

Parameters
runNowExecute the callback right now instead of adding it the queue.
tagSee enabled().
defDefault value for enabled().
virtual void DtParallelTickManager::addCallback ( SerialCallbackInterface ,
const std::string &  tag,
bool  def = true 
)
virtual

Add callbacks to the queue.

The pointer versions take ownership of their callbacks. The reference versions do not and require the caller to keep them alive. The container versions add an STL-like container of callbacks.

Parameters
runNowExecute the callback right now instead of adding it the queue.
tagSee enabled().
defDefault value for enabled().
void DtParallelTickManager::addCallback ( CallbackInterface ,
const char tag,
bool  def = true 
)

Add callbacks to the queue.

The pointer versions take ownership of their callbacks. The reference versions do not and require the caller to keep them alive. The container versions add an STL-like container of callbacks.

Parameters
runNowExecute the callback right now instead of adding it the queue.
tagSee enabled().
defDefault value for enabled().
void DtParallelTickManager::addCallback ( CallbackInterface ,
const char tag,
bool  def = true 
)

Add callbacks to the queue.

The pointer versions take ownership of their callbacks. The reference versions do not and require the caller to keep them alive. The container versions add an STL-like container of callbacks.

Parameters
runNowExecute the callback right now instead of adding it the queue.
tagSee enabled().
defDefault value for enabled().
void DtParallelTickManager::addCallback ( SerialCallbackInterface ,
const char tag,
bool  def = true 
)

Add callbacks to the queue.

The pointer versions take ownership of their callbacks. The reference versions do not and require the caller to keep them alive. The container versions add an STL-like container of callbacks.

Parameters
runNowExecute the callback right now instead of adding it the queue.
tagSee enabled().
defDefault value for enabled().
void DtParallelTickManager::addCallback ( SerialCallbackInterface ,
const char tag,
bool  def = true 
)

Add callbacks to the queue.

The pointer versions take ownership of their callbacks. The reference versions do not and require the caller to keep them alive. The container versions add an STL-like container of callbacks.

Parameters
runNowExecute the callback right now instead of adding it the queue.
tagSee enabled().
defDefault value for enabled().
template<typename Container >
void DtParallelTickManager::addCallbacks ( Container &  cont,
bool  runNow = false 
)
inline

Add callbacks to the queue.

The pointer versions take ownership of their callbacks. The reference versions do not and require the caller to keep them alive. The container versions add an STL-like container of callbacks.

Parameters
runNowExecute the callback right now instead of adding it the queue.
tagSee enabled().
defDefault value for enabled().

References addCallback().

Referenced by addCallbacks().

template<typename Container >
void DtParallelTickManager::addCallbacks ( Container &  cont,
const std::string &  tag,
bool  def = true 
)
inline

Add callbacks to the queue.

The pointer versions take ownership of their callbacks. The reference versions do not and require the caller to keep them alive. The container versions add an STL-like container of callbacks.

Parameters
runNowExecute the callback right now instead of adding it the queue.
tagSee enabled().
defDefault value for enabled().

References addCallback(), and enabled().

template<typename Container >
void DtParallelTickManager::addCallbacks ( Container &  cont,
const char tag,
bool  def = true 
)
inline

Add callbacks to the queue.

The pointer versions take ownership of their callbacks. The reference versions do not and require the caller to keep them alive. The container versions add an STL-like container of callbacks.

Parameters
runNowExecute the callback right now instead of adding it the queue.
tagSee enabled().
defDefault value for enabled().

References addCallbacks().

virtual void DtParallelTickManager::lock ( )
privatevirtual

Manipulate global mutex.

virtual void DtParallelTickManager::unlock ( )
privatevirtual

Manipulate global mutex.

virtual void DtParallelTickManager::readLock ( )
privatevirtual

Manipulate global mutex.

virtual void DtParallelTickManager::readUnlock ( )
privatevirtual

Manipulate global mutex.

virtual bool DtParallelTickManager::upgradeToWriter ( )
privatevirtual

Manipulate global mutex.

virtual void DtParallelTickManager::downgradeToReader ( )
privatevirtual

Manipulate global mutex.

virtual void DtParallelTickManager::createCallbackQueue ( bool  force = false)
privatevirtual

Create the callback queue.

Member Data Documentation

Mutex DtParallelTickManager::myMutex
private
Condition DtParallelTickManager::myCondition
private
size_t DtParallelTickManager::myReaderCount
private
DtVrfSimOptionsInterface* DtParallelTickManager::myOptions
private
DtCallbackQueue* DtParallelTickManager::myCallbackQueue
private
EnabledMap DtParallelTickManager::myEnabledMap
mutableprivate
bool DtParallelTickManager::myWaitFlag
private
DtSubCommandManager* DtParallelTickManager::myCommandManager
private
DtConsoleCommandOwner* DtParallelTickManager::myCommandOwner
private

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

Document ID: Generated on Wed Mar 11 21:20:57 EDT 2015 from SVN revision 150940
Copyright © 2005-2014 VT MÄK. All Rights Reserved (www.mak.com)