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

Stores data about a single work unit so that it can easily be sorted. More...

#include <workunitkey.h>

+ Collaboration diagram for Mezzanine::Threading::WorkUnitKey:

Public Member Functions

 WorkUnitKey ()
 Default Constructor. More...
 
 WorkUnitKey (const Whole &Dependers_, const Whole &Time_, iWorkUnit *WorkUnit_)
 Constructor. More...
 
virtual ~WorkUnitKey ()
 Destructor.
 
virtual bool operator< (const WorkUnitKey &rhs) const
 The function that does the comparison in most containers. More...
 
virtual bool operator== (const WorkUnitKey &rhs) const
 Does this key point to the Same work unit as another? More...
 

Public Attributes

Whole Dependers
 This stores how many things must run after the target workunit. More...
 
Whole Time
 Some representation of the time the target workunit takes to execute. More...
 
iWorkUnitUnit
 The WorkUnit this carries metadata for.
 

Detailed Description

Stores data about a single work unit so that it can easily be sorted.

Definition at line 56 of file workunitkey.h.

Constructor & Destructor Documentation

Mezzanine::Threading::WorkUnitKey::WorkUnitKey ( )

Default Constructor.

This creates an empty and quite useless Key, needs to be filled with data before being useful.

Definition at line 54 of file workunitkey.cpp.

Mezzanine::Threading::WorkUnitKey::WorkUnitKey ( const Whole Dependers_,
const Whole Time_,
iWorkUnit WorkUnit_ 
)

Constructor.

Parameters
Dependers_How many items depend on this. This needs to be calculated the same for all WorkUnitKeys.
Time_How long is this workunit expected to execute for. This needs to be calculated the same for all WorkUnitKeys.
WorkUnit_A pointer to the workunit in question.

Definition at line 58 of file workunitkey.cpp.

Member Function Documentation

bool Mezzanine::Threading::WorkUnitKey::operator< ( const WorkUnitKey rhs) const
virtual

The function that does the comparison in most containers.

Parameters
rhsThe right hand WorkUnitKey when using <.

This enforces the algorithm that sorts workunits. The workunit with the most other work units depending on it is priotized first. Because the longest delays in execution time can be introduced if WorkUnits are waiting for a dependency and it is poorly scheduled, this can results in single threaded execution when more could have been possible. If there is a tie in dependent count, then the work unit that takes longer to execute is prioritized (this needs to be tested for correctness). This starts WorkUnits that take longer earlier in the frame, helping to minimize the length of the critical path. In the event that those are both tied, then the WorkUnit with the lowest pointer value is priotized to prevent any of WorkUnitKey from comparing identically.

Returns
True if the left hand WorkUnit should be prioritized ahead of the right hand work unit.

Definition at line 65 of file workunitkey.cpp.

bool Mezzanine::Threading::WorkUnitKey::operator== ( const WorkUnitKey rhs) const
virtual

Does this key point to the Same work unit as another?

Parameters
rhsThe other key.
Returns
True if the both keys are for the same unit, other parameters are ignored.

Definition at line 79 of file workunitkey.cpp.

Member Data Documentation

Whole Mezzanine::Threading::WorkUnitKey::Dependers

This stores how many things must run after the target workunit.

This is most important sorting factor. In the Default algorithm. All of the Workunit that the most workunits depend on are run before the any others. Since this number is usually low (less than 10ish) in large groups of workunits, then there must be a tie-breaker. This should be calculated including the dependers of all the dependers (I don't think counting a workunit twice hurts, and it may even help if something actually depend on multiple workunits that depend on this.)

Note
I chose the word depender instead of dependent, to make the distinction between this field and dependencies more clear when communicated verbally. In some english dialects dependencies is pronounced Dee-pen-dent-sees only one syllable off from Dee-pen-dent.

Definition at line 71 of file workunitkey.h.

Whole Mezzanine::Threading::WorkUnitKey::Time

Some representation of the time the target workunit takes to execute.

In the default algorithm this is used to determine what executes first after dependents are counted. It is important to know what takes the longest time and start it first so that it might finish coterminously with shorter workunits. This is used second because length of execution of one workunit means nothing if many other workunits run serialized in one thread rather than in parrellel.

Definition at line 80 of file workunitkey.h.


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