Spinning Topp Logo BlackTopp Studios
inc
workunitkey.h
Go to the documentation of this file.
1 // The DAGFrameScheduler is a Multi-Threaded lock free and wait free scheduling library.
2 // © Copyright 2010 - 2016 BlackTopp Studios Inc.
3 /* This file is part of The DAGFrameScheduler.
4 
5  The DAGFrameScheduler is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  The DAGFrameScheduler is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with The DAGFrameScheduler. If not, see <http://www.gnu.org/licenses/>.
17 */
18 /* The original authors have included a copy of the license specified above in the
19  'doc' folder. See 'gpl.txt'
20 */
21 /* We welcome the use of the DAGFrameScheduler to anyone, including companies who wish to
22  Build professional software and charge for their product.
23 
24  However there are some practical restrictions, so if your project involves
25  any of the following you should contact us and we will try to work something
26  out:
27  - DRM or Copy Protection of any kind(except Copyrights)
28  - Software Patents You Do Not Wish to Freely License
29  - Any Kind of Linking to Non-GPL licensed Works
30  - Are Currently In Violation of Another Copyright Holder's GPL License
31  - If You want to change our code and not add a few hundred MB of stuff to
32  your distribution
33 
34  These and other limitations could cause serious legal problems if you ignore
35  them, so it is best to simply contact us or the Free Software Foundation, if
36  you have any questions.
37 
38  Joseph Toppi - toppij@gmail.com
39  John Blackwood - makoenergy02@gmail.com
40 */
41 #ifndef _timeddagworkunitkey_h
42 #define _timeddagworkunitkey_h
43 
44 #include "datatypes.h"
45 
46 /// @file
47 /// @brief This file defines the metadata used to sort workunits.
48 
49 namespace Mezzanine
50 {
51  namespace Threading
52  {
53  class iWorkUnit;
54 
55  /// @brief Stores data about a single work unit so that it can easily be sorted.
57  {
58  public:
59  /// @brief The WorkUnit this carries metadata for.
61 
62  /// @brief This stores how many things must run after the target workunit.
63  /// @details This is most important sorting factor. In the Default algorithm.
64  /// All of the Workunit that the most workunits depend on are run before the
65  /// any others. Since this number is usually low (less than 10ish) in large
66  /// groups of workunits, then there must be a tie-breaker. This should be
67  /// calculated including the dependers of all the dependers (I don't think
68  /// counting a workunit twice hurts, and it may even help if something
69  /// actually depend on multiple workunits that depend on this.)
70  /// @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.
72 
73  /// @brief Some representation of the time the target workunit takes to execute.
74  /// @details In the default algorithm this is used to determine what executes
75  /// first after dependents are counted. It is important to know what takes the longest time
76  /// and start it first so that it might finish coterminously with shorter
77  /// workunits. This is used second because length of execution of one workunit
78  /// means nothing if many other workunits run serialized in one thread rather than
79  /// in parrellel.
81 
82  /// @brief Default Constructor
83  /// @details This creates an empty and quite useless Key, needs to be filled with data before being useful.
84  WorkUnitKey();
85 
86  /// @brief Constructor
87  /// @param Dependers_ How many items depend on this. This needs to be calculated the same for all WorkUnitKeys.
88  /// @param Time_ How long is this workunit expected to execute for. This needs to be calculated the same for all WorkUnitKeys.
89  /// @param WorkUnit_ A pointer to the workunit in question.
90  WorkUnitKey(const Whole& Dependers_, const Whole& Time_, iWorkUnit* WorkUnit_);
91 
92  /// @brief Destructor
93  virtual ~WorkUnitKey();
94 
95  /// @brief The function that does the comparison in most containers.
96  /// @param rhs The right hand WorkUnitKey when using <.
97  /// @details This enforces the algorithm that sorts workunits. The workunit with the most
98  /// other work units depending on it is priotized first. Because the longest delays in
99  /// execution time can be introduced if WorkUnits are waiting for a dependency and it is
100  /// poorly scheduled, this can results in single threaded execution when more could have
101  /// been possible. If there is a tie in dependent count, then the work unit that takes
102  /// longer to execute is prioritized (this needs to be tested for correctness). This
103  /// starts WorkUnits that take longer earlier in the frame, helping to minimize the
104  /// length of the critical path. In the event that those are both tied, then the WorkUnit
105  /// with the lowest pointer value is priotized to prevent any of WorkUnitKey from comparing
106  /// identically.
107  /// @return True if the left hand WorkUnit should be prioritized ahead of the right hand work unit.
108  virtual bool operator< (const WorkUnitKey& rhs ) const;
109 
110  /// @brief Does this key point to the Same work unit as another?
111  /// @param rhs The other key.
112  /// @return True if the both keys are for the same unit, other parameters are ignored.
113  virtual bool operator== (const WorkUnitKey& rhs ) const;
114  };//WorkUnitKey
115  }//Threading
116 }//Mezzanine
117 #endif
Whole Time
Some representation of the time the target workunit takes to execute.
Definition: workunitkey.h:80
Whole Dependers
This stores how many things must run after the target workunit.
Definition: workunitkey.h:71
Stores data about a single work unit so that it can easily be sorted.
Definition: workunitkey.h:56
All the definitions for datatypes as well as some basic conversion functions are defined here...
Interface of a WorkUnit. This represents on piece of work through time.
Definition: workunit.h:66
iWorkUnit * Unit
The WorkUnit this carries metadata for.
Definition: workunitkey.h:60
#define MEZZ_LIB
Some platforms require special decorations to denote what is exported/imported in a share library...
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
unsigned long Whole
Whole is an unsigned integer, it will be at least 32bits in size.
Definition: datatypes.h:151