Spinning Topp Logo BlackTopp Studios
inc
Public Member Functions | Protected Attributes | List of all members
Mezzanine::Threading::DefaultWorkUnit Class Reference

Default implementation of WorkUnit. This represents on piece of work through time. More...

#include <workunit.h>

+ Inheritance diagram for Mezzanine::Threading::DefaultWorkUnit:
+ Collaboration diagram for Mezzanine::Threading::DefaultWorkUnit:

Public Member Functions

 DefaultWorkUnit ()
 Simple constructor.
 
virtual ~DefaultWorkUnit ()
 Virtual destructor, doesn't actually do much.
 
virtual void AddDependency (iWorkUnit *NewDependency)
 Force this WorkUnit to Start after another has completed. More...
 
virtual void ClearDependencies ()
 Drop any information about what work units this one depends on.
 
virtual iWorkUnitGetDependency (Whole Index) const
 This is used to iterate of all the dependencies. More...
 
virtual Whole GetDependencyCount () const
 How many other WorkUnits does this one depend on? More...
 
virtual Whole GetDependentCount (FrameScheduler &SchedulerToCount)
 This returns the count workunits that depend on this work unit. More...
 
virtual Whole GetImmediateDependencyCount () const
 Get the amount of dependencies that directly count on this for access purposes. More...
 
virtual Whole GetPerformance () const
 Get the internal rolling average for querying. More...
 
virtual RollingAverage< Whole > & GetPerformanceLog ()
 Get the internal rolling average for querying. More...
 
virtual RunningState GetRunningState () const
 Retrieves the current RunningState of the thread. More...
 
virtual WorkUnitKey GetSortingKey (FrameScheduler &SchedulerToCount)
 Get the sorting metadata. More...
 
virtual bool IsEveryDependencyComplete ()
 Check if this WorkUnit could concievably run right now. More...
 
virtual void operator() (DefaultThreadSpecificStorage::Type &CurrentThreadStorage)
 This does everything required to track metadata and log work. More...
 
virtual void PrepareForNextFrame ()
 This resets the running state and takes any further action required to use the WorkUnit again.
 
virtual void RemoveDependency (iWorkUnit *RemoveDependency)
 Remove a dependency. More...
 
virtual RunningState TakeOwnerShip ()
 Attempts to atomically start the work unit in the current thread. More...
 
- Public Member Functions inherited from Mezzanine::Threading::iWorkUnit
virtual ~iWorkUnit ()
 Virtual destructor.
 
virtual void DoWork (DefaultThreadSpecificStorage::Type &CurrentThreadStorage)=0
 WorkUnits Must implement these to do the work.
 

Protected Attributes

Int32 CurrentRunningState
 This controls do work with this after it has.
 
std::vector< iWorkUnit * > Dependencies
 A collection of of workunits that must be complete before this one can start.
 
DefaultRollingAverage< Whole >::Type PerformanceLog
 A rolling average of execution times.
 

Detailed Description

Default implementation of WorkUnit. This represents on piece of work through time.

Definition at line 160 of file workunit.h.

Member Function Documentation

void Mezzanine::Threading::DefaultWorkUnit::AddDependency ( iWorkUnit NewDependency)
virtual

Force this WorkUnit to Start after another has completed.

Parameters
NewDependencyThe WorkUnit that must start after this one has completed.
Warning
Changing this outside the schedule, once the scheduler has started can cause undefined behavior.

Implements Mezzanine::Threading::iWorkUnit.

Definition at line 99 of file workunit.cpp.

iWorkUnit * Mezzanine::Threading::DefaultWorkUnit::GetDependency ( Whole  Index) const
virtual

This is used to iterate of all the dependencies.

Parameters
IndexThe 0 based index of the dependency you are trying to retrieve. No ordering is guaranteed, just that counting from 0 to GetImmediateDependencyCount() with access each iWorkUnit once.
Returns
A pointer to an iWorkUnit.

Implements Mezzanine::Threading::iWorkUnit.

Definition at line 84 of file workunit.cpp.

Whole Mezzanine::Threading::DefaultWorkUnit::GetDependencyCount ( ) const
virtual

How many other WorkUnits does this one depend on?

This is what the FrameScheduler uses to calculate the sorting order of WorkUnits. In the default implmentation it counts some units twice if they depend on this WorkUnit through Multiple dependency chains.

Returns
A Whole containing the answer.

Implements Mezzanine::Threading::iWorkUnit.

Definition at line 90 of file workunit.cpp.

Whole Mezzanine::Threading::DefaultWorkUnit::GetDependentCount ( FrameScheduler SchedulerToCount)
virtual

This returns the count workunits that depend on this work unit.

Parameters
SchedulerToCountThe FrameScheduler has a cache of this data, it is impossible to calculate without the complete list of WorkUnits on it either.

Because Dependents are not tracked this iterates over entry in the FrameScheduler it is passed.

Returns
A Whole is returned containing the count.

Implements Mezzanine::Threading::iWorkUnit.

Definition at line 78 of file workunit.cpp.

Whole Mezzanine::Threading::DefaultWorkUnit::GetImmediateDependencyCount ( ) const
virtual

Get the amount of dependencies that directly count on this for access purposes.

Returns
The amount of accessable WorkUnit from this WorkUnits dependency list.

Implements Mezzanine::Threading::iWorkUnit.

Definition at line 87 of file workunit.cpp.

Whole Mezzanine::Threading::DefaultWorkUnit::GetPerformance ( ) const
virtual

Get the internal rolling average for querying.

Returns
A whole that represents this WorkUnits Performance.

Implements Mezzanine::Threading::iWorkUnit.

Definition at line 145 of file workunit.cpp.

RollingAverage< Whole > & Mezzanine::Threading::DefaultWorkUnit::GetPerformanceLog ( )
virtual

Get the internal rolling average for querying.

Returns
A const reference to the internal Rolling Average.

Definition at line 148 of file workunit.cpp.

RunningState Mezzanine::Threading::DefaultWorkUnit::GetRunningState ( ) const
virtual

Retrieves the current RunningState of the thread.

Returns
A RunningState that indicates if the thread is running, started, etc... This information can be changed at any time and should be considered stale immediately after retrieval.

Implements Mezzanine::Threading::iWorkUnit.

Definition at line 136 of file workunit.cpp.

WorkUnitKey Mezzanine::Threading::DefaultWorkUnit::GetSortingKey ( FrameScheduler SchedulerToCount)
virtual

Get the sorting metadata.

Parameters
SchedulerToCountThis uses the metadata on the FrameScheduler to generate the Dependency listing required.
Returns
A WorkUnitKey suitable for sorting this workunit.

Implements Mezzanine::Threading::iWorkUnit.

Definition at line 175 of file workunit.cpp.

bool Mezzanine::Threading::DefaultWorkUnit::IsEveryDependencyComplete ( )
virtual

Check if this WorkUnit could concievably run right now.

Returns
This returns true if all of this WorkUnits dependencies have completed execution and false otherwise.

Implements Mezzanine::Threading::iWorkUnit.

Definition at line 113 of file workunit.cpp.

void Mezzanine::Threading::DefaultWorkUnit::operator() ( DefaultThreadSpecificStorage::Type CurrentThreadStorage)
virtual

This does everything required to track metadata and log work.

Parameters
CurrentThreadStorageThe FrameScheduler passes this in

This wraps the log output in a WorkUnit element with a unique ID as and an attribute. This causes all the log output to be valid xml as long no '<' or '>' are emitted.

Implements Mezzanine::Threading::iWorkUnit.

Definition at line 154 of file workunit.cpp.

void Mezzanine::Threading::DefaultWorkUnit::RemoveDependency ( iWorkUnit RemoveDependency)
virtual

Remove a dependency.

Parameters
RemoveDependencyA pointer to the WorkUnit to remove as a dependency.

Implements Mezzanine::Threading::iWorkUnit.

Definition at line 102 of file workunit.cpp.

RunningState Mezzanine::Threading::DefaultWorkUnit::TakeOwnerShip ( )
virtual

Attempts to atomically start the work unit in the current thread.

Returns
Returns RunningState::Starting if this thread was able to gain ownership and start the workunit, returns RunningState::NotStarted otherwise.

Implements Mezzanine::Threading::iWorkUnit.

Definition at line 125 of file workunit.cpp.


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