Spinning Topp Logo BlackTopp Studios
inc
frameschedulerworkunits.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 
42 #ifndef _frameschedulerworkunits_h
43 #define _frameschedulerworkunits_h
44 
45 #include "datatypes.h"
46 
47 #if !defined(SWIG) || defined(SWIG_THREADING) // Do not read when in swig and not in the threading module
48 #include "workunit.h"
49 #include "workunitkey.h"
50 #endif
51 /// @file
52 /// @brief This defines a number of workunits that are required for doing some tasks that the Framescheduler requires.
53 
54 namespace Mezzanine
55 {
56  namespace Threading
57  {
58  // Forward Declare
59  class FrameScheduler;
60 
61  /// @brief Gather all the thread specific logs and commit them to the main log.
62  /// @details All the logs are double buffered. This reads from the commitable buffer
63  /// which should otherwise be unused. This task was separated from the log swapper
64  /// top minimize contention.
66  {
67  private:
68  /// @brief The frameScheduler to aggregate;
69  /// @note On Linux AMD64 this pointer brings the size of this class to 64 bytes a common cache line size.
70  FrameScheduler* AggregationTarget;
71 
72  /// @brief Used to signal any special condition that forced an abnormal log flush
73  Boole ForcedLog;
74 
75  public:
76  /// @brief Create a default log agregator with no target
77  LogAggregator();
78 
79  /// @brief Virtual Deconstructor
80  virtual ~LogAggregator();
81 
82  /// @brief Used to indicate the next log flush is abnormally forced
83  /// @param Force Can be passed to unset the abnormal log flush.
84  void NextFlushForced(Boole Force=true);
85 
86  /// @brief This does the actual work of log aggregation.
87  /// @param CurrentThreadStorage This is used to retrieve the framescheduler that will have its log aggregated.
88  /// @details If there is no currently set aggregation target this sets it to whatever scheduler is in
89  /// the passed ThreadSpecificStorage
90  virtual void DoWork(DefaultThreadSpecificStorage::Type& CurrentThreadStorage);
91 
92  /// @brief Get the current Aggregation Target
93  /// @return A FrameScheduler pointer or NULL if one is not set
94  FrameScheduler* GetAggregationTarget() const;
95 
96  /// @brief Set which framescheduler will be aggregated.
97  /// @param NewTarget A pointer to the FrameScheduler to aggregate.
98  /// @details If set to NULL this will use whatever FrameScheduler is in the next
99  /// ThreadSpecificStorage passed during DoWork. This will never delete a framescheduler.
100  void SetAggregationTarget(FrameScheduler* NewTarget);
101  }; //LogAggregator
102 
103  /// @brief Sorts all of the WorkUnits in the @ref FrameScheduler.
105  {
106  friend class FrameScheduler;
107  protected:
108  /// @brief 1 in every this many frames Sorting happens.
110 
111  /// @brief How long since the last sort?
113 
114  /// @brief A freshly sorted WorkUnitsMain or an empty vector.
115  std::vector<WorkUnitKey> WorkUnitsMain;
116 
117  /// @brief A freshly sorted WorkUnitsAffinity or an empty vector.
118  std::vector<WorkUnitKey> WorkUnitsAffinity;
119 
120  public:
121  /// @brief Default constructor.
122  WorkSorter();
123 
124  /// @brief This usually does nothing, but sometimes it will do a whole bunch of work sorting.
125  /// @param CurrentThreadStorage Just to get a reference to the framescheduler. So the WorkUnits can sorted and passed back to the Scheduler outisde of scheduling.
126  virtual void DoWork(DefaultThreadSpecificStorage::Type& CurrentThreadStorage);
127 
128  /// @brief Set how often this actually does work
129  /// @param FramesBetweenSorts 1 in every this many frame this will sort the work units.
130  virtual void SetSortingFrequency(Whole FramesBetweenSorts);
131 
132  /// @brief Check how often this sorts.
133  /// @return A Whole containing the sorting frequency.
134  virtual Whole GetSortingFrequency();
135  };//WorkSorter
136  }//Threading
137 }//Mezzanine
138 
139 #endif
bool Boole
Generally acts a single bit, true or false.
Definition: datatypes.h:173
Default implementation of WorkUnit. This represents on piece of work through time.
Definition: workunit.h:160
Whole FramesSinceLastSort
How long since the last sort?
All the definitions for datatypes as well as some basic conversion functions are defined here...
std::vector< WorkUnitKey > WorkUnitsAffinity
A freshly sorted WorkUnitsAffinity or an empty vector.
Whole SortingFrequency
1 in every this many frames Sorting happens.
A thread specific collection of double-buffered and algorithm specific resources. ...
Sorts all of the WorkUnits in the FrameScheduler.
std::vector< WorkUnitKey > WorkUnitsMain
A freshly sorted WorkUnitsMain or an empty vector.
This is central object in this algorithm, it is responsible for spawning threads and managing the ord...
This file defines the metadata used to sort workunits.
Gather all the thread specific logs and commit them to the main log.
#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
This file has the definition of the workunit.