MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
frameschedulerworkunits.cpp
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 #ifndef _frameschedulerworkunits_cpp
42 #define _frameschedulerworkunits_cpp
43 
45 #include "doublebufferedresource.h"
46 
47 /// @file
48 /// @brief The implementation of any workunits the framescheduler needs to work correctly
49 
50 namespace Mezzanine
51 {
52  namespace Threading
53  {
54 
55  LogAggregator::LogAggregator() : AggregationTarget(NULL)
56  {}
57 
59  {}
60 
62  {
63  if(!AggregationTarget)
64  { AggregationTarget = CurrentThreadStorage.GetFrameScheduler(); }
65  AggregationTarget->LogResources.Lock();
66 
67  std::ostream& Log = AggregationTarget->GetLog();
68  Log << "<Frame Count=\"" << AggregationTarget->GetFrameCount() << "\">" << std::endl;
69  for(std::vector<DefaultThreadSpecificStorage::Type*>::const_iterator Iter=AggregationTarget->Resources.begin();
70  Iter!=AggregationTarget->Resources.end();
71  ++Iter)
72  {
73  Log << "<Thread Main=\"" << (AggregationTarget->Resources.begin()==Iter?1:0)<< "\">" << std::endl
74  << (*Iter)->GetResource<DoubleBufferedLogger>(DBRLogger).GetCommittable().str()
75  << "</Thread>" << std::endl;
76  (*Iter)->GetResource<DoubleBufferedLogger>(DBRLogger).GetCommittable().str("");
77  }
78  AggregationTarget->LogResources.Unlock();
79  Log << "</Frame>" << std::endl;
80  }
81 
82 
84  { return AggregationTarget; }
85 
87  { AggregationTarget = NewTarget; }
88 
90  SortingFrequency(MEZZ_FRAMESTOTRACK*2),
91  FramesSinceLastSort(0)
92  {}
93 
95  {
98  {
99  #ifdef MEZZ_DEBUG
100  CurrentThreadStorage.GetResource<DoubleBufferedLogger>(DBRLogger).GetUsable() << "<SortWork sorting=\"0\" ThreadID=\"" << Mezzanine::Threading::this_thread::get_id() << "\" />" << std::endl;
101  #endif
103  FrameScheduler& FS = *CurrentThreadStorage.GetFrameScheduler();
104  //WorkUnitsMain.clear(); // should be cleared by the framescheduler or whatever copies this into the framscheduler
105  //WorkUnitsAffinity.clear();
106  WorkUnitsMain.clear();
107  WorkUnitsAffinity.clear();
108  WorkUnitsMain.insert(WorkUnitsMain.end(),FS.WorkUnitsMain.begin(),FS.WorkUnitsMain.end());
112  FS.Sorter = this;
113  }else{
114  #ifdef MEZZ_DEBUG
115  CurrentThreadStorage.GetResource<DoubleBufferedLogger>(DBRLogger).GetUsable() << "<SortWork sorting=\"1\" ThreadID=\"" << Mezzanine::Threading::this_thread::get_id() << "\" />" << std::endl;
116  #endif
117  }
118  }
119 
120  void WorkSorter::SetSortingFrequency(Whole FramesBetweenSorts)
121  { SortingFrequency = FramesBetweenSorts; }
122 
124  { return SortingFrequency; }
125 
126  }//Threading
127 }//Mezzanine
128 
129 
130 #endif