MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 - 2014 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  public:
73  /// @brief Create a default log agregator with no target
74  LogAggregator();
75 
76  /// @brief Virtual Deconstructor
77  virtual ~LogAggregator();
78 
79  /// @brief This does the actual work of log aggregation.
80  /// @param CurrentThreadStorage This is used to retrieve the framescheduler that will have its log aggregated.
81  /// @details If there is no currently set aggregation target this sets it to whatever scheduler is in
82  /// the passed ThreadSpecificStorage
83  virtual void DoWork(DefaultThreadSpecificStorage::Type& CurrentThreadStorage);
84 
85  /// @brief Get the current Aggregation Target
86  /// @return A FrameScheduler pointer or NULL if one is not set
87  FrameScheduler* GetAggregationTarget() const;
88 
89  /// @brief Set which framescheduler will be aggregated.
90  /// @param NewTarget A pointer to the FrameScheduler to aggregate.
91  /// @details If set to NULL this will use whatever FrameScheduler is in the next
92  /// ThreadSpecificStorage passed during DoWork. This will never delete a framescheduler.
93  void SetAggregationTarget(FrameScheduler* NewTarget);
94  }; //LogAggregator
95 
96  /// @brief Sorts all of the WorkUnits in the @ref FrameScheduler.
98  {
99  friend class FrameScheduler;
100  protected:
101  /// @brief 1 in every this many frames Sorting happens.
103 
104  /// @brief How long since the last sort?
106 
107  /// @brief A freshly sorted WorkUnitsMain or an empty vector.
108  std::vector<WorkUnitKey> WorkUnitsMain;
109 
110  /// @brief A freshly sorted WorkUnitsAffinity or an empty vector.
111  std::vector<WorkUnitKey> WorkUnitsAffinity;
112 
113  public:
114  /// @brief Default constructor.
115  WorkSorter();
116 
117  /// @brief This usually does nothing, but sometimes it will do a whole bunch of work sorting.
118  /// @param CurrentThreadStorage Just to get a reference to the framescheduler. So the WorkUnits can sorted and passed back to the Scheduler outisde of scheduling.
119  virtual void DoWork(DefaultThreadSpecificStorage::Type& CurrentThreadStorage);
120 
121  /// @brief Set how often this actually does work
122  /// @param FramesBetweenSorts 1 in every this many frame this will sort the work units.
123  virtual void SetSortingFrequency(Whole FramesBetweenSorts);
124 
125  /// @brief Check how often this sorts.
126  /// @return A Whole containing the sorting frequency.
127  virtual Whole GetSortingFrequency();
128  };//WorkSorter
129  }//Threading
130 }//Mezzanine
131 
132 #endif