41 #ifndef _framescheduler_h
42 #define _framescheduler_h
46 #if !defined(SWIG) || defined(SWIG_THREADING) // Do not read when in swig and not in the threading module
62 class MonopolyWorkUnit;
77 friend void TerminateHandler();
169 #ifdef MEZZ_USEATOMICSTODECACHECOMPLETEWORK
174 Int32 DecacheAffinity;
211 static void RemoveErrorScheduler(
FrameScheduler* SchedulerToRemove);
214 void CleanUpThreads();
217 void DeleteThreads();
221 void UpdateDependentGraph(
const std::vector<WorkUnitKey> &Units);
225 void UpdateWorkUnitKeys(std::vector<WorkUnitKey> &Units);
237 std::fstream* _LogDestination = 0,
246 std::ostream* _LogDestination,
251 void SetErrorHandler();
263 virtual void AddWorkUnitMain(iWorkUnit* MoreWork,
const String& WorkUnitName);
268 virtual void AddWorkUnitAffinity(iWorkUnit* MoreWork,
const String& WorkUnitName);
279 virtual void SortWorkUnitsMain(
bool UpdateDependentGraph_ =
true);
285 virtual void SortWorkUnitsAffinity(
bool UpdateDependentGraph_ =
true);
291 virtual void SortWorkUnitsAll(
bool UpdateDependentGraph_ =
true);
300 virtual void RemoveWorkUnitMain(iWorkUnit* LessWork);
304 virtual void RemoveWorkUnitAffinity(iWorkUnit* LessWork);
317 virtual Whole GetDependentCountOf(iWorkUnit *Work,
bool UsedCachedDepedentGraph=
false);
323 virtual iWorkUnit* GetNextWorkUnit();
327 virtual iWorkUnit* GetNextWorkUnitAffinity();
331 virtual bool AreAllWorkUnitsComplete();
336 virtual void UpdateDependentGraph();
343 virtual Whole GetFrameCount()
const;
347 virtual Whole GetFrameLength()
const;
357 virtual void SetFrameRate(
const Whole& FrameRate);
361 virtual void SetFrameLength(
const Whole& FrameLength);
365 virtual Whole GetThreadCount();
370 virtual void SetThreadCount(
const Whole& NewThreadCount);
374 virtual MaxInt GetCurrentFrameStart()
const;
382 Whole GetLastPauseTime()
const;
390 Whole GetLastFrameTime()
const;
414 virtual void DoOneFrame();
425 virtual void RunAllMonopolies();
441 virtual void CreateThreads();
456 virtual void RunMainThreadWork();
467 void JoinAllThreads();
477 virtual void ResetAllWorkUnits();
489 void WaitUntilNextFrame();
498 Whole GetWorkUnitMonopolyCount()
const;
502 Whole GetWorkUnitAffinityCount()
const;
506 Whole GetWorkUnitMainCount()
const;
537 void DependenciesChanged(
bool Changed=
true);
541 void LogDependencies();
546 std::ostream& GetLog();
548 void ChangeLogTarget(std::ostream* LogTarget);
551 void InstallLog(std::ostream* LogTarget);
565 virtual Boole ForceLogFlush();
569 void SwapBufferedResources();
int32_t Int32
An 32-bit integer.
Use this to get the default rolling average for a given type.
std::vector< WorkUnitKey >::const_iterator ConstIteratorMain
A const iterator suitable for iterating over the main pool of work units.
ThreadId MEZZ_LIB get_id()
Return the thread ID of the calling thread.
std::stringstream Logger
In case we ever replace the stringstream with another class, this will allow us to swap it out...
bool Boole
Generally acts a single bit, true or false.
std::vector< WorkUnitKey > WorkUnitsAffinity
A collection of iWorkUnits that must be run on the main thread.
std::vector< Resource * > Resources
This maintains ownership of all the thread specific resources.
Whole TargetFrameLength
The Maximum frame rate this algorithm should run at.
bool LoggingToAnOwnedFileStream
Set based on which constructor is called, and only used during destruction.
Integer TimingCostAllowance
To prevent frame time drift this many microseconds is subtracted from the wait period to allow time f...
Declares a Mutex, Mutex tools, and at least one MutexLike object.
All the definitions for datatypes as well as some basic conversion functions are defined here...
int Integer
A datatype used to represent any integer close to.
DependentGraphType DependentGraph
This structure allows reverse lookup of dependencies.
Interface of a WorkUnit. This represents on piece of work through time.
std::ostream * LogDestination
When the logs are aggregated, this is where they are sent.
std::vector< WorkUnitKey >::iterator IteratorMain
An iterator suitable for iterating over the main pool of work units.
This file defines the template double buffered resources that can be attached to a thread...
std::vector< WorkUnitKey >::const_iterator ConstIteratorAffinity
A const iterator suitable for iterating over the main pool of work units.
This file defines a minimalistic cross-platform thread that the scheduler uses to schedule tasks...
A kind of workunit given exclusive runtime so it can consume time on multiple threads.
bool NeedToLogDeps
Brief Do we have to log ependencies have they changed since last logged?
Whole FrameCount
Used to store a count of frames from the begining of game execution.
static SpinLock FrameSchedulersLock
A lock that protects the list frame schedulers, for use in the event of an error. ...
A thread specific collection of double-buffered and algorithm specific resources. ...
Whole MEZZ_LIB GetCPUCount()
Get the amount of logical processors, a reasononable amount to use for thread creation.
std::vector< WorkUnitKey > WorkUnitsMain
A collection of all the work units that are not Monopolies and do not have affinity for a given threa...
std::vector< MonopolyWorkUnit * >::iterator IteratorMonoply
An iterator suitable for iterating over the main pool of work units.
Sorts all of the WorkUnits in the FrameScheduler.
MaxInt CurrentPauseStart
What time did the current Frame Start at.
SpinLock LogResources
Protects DoubleBufferedResources during creation and error handling from being accessed by the LogAgg...
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.
std::vector< WorkUnitKey >::iterator IteratorAffinity
An iterator suitable for iterating over the main pool of work units.
std::map< iWorkUnit *, std::set< iWorkUnit * > > DependentGraphType
A structure designed to minimalistically represent Dependency and Reverse Dependency Graphs in work u...
This stores the implementation and the declaration of the RollingAverage, BufferedRollingAverage, WeightedRollingAverage and the DefaultRollingAverage.
static std::vector< FrameScheduler * > FrameSchedulers
A list frame schedulers, for use in the event of an error.
Gather all the thread specific logs and commit them to the main log.
A mutex like construct that never makes a system call and uses CPU instructions instead.
std::vector< Thread * > Threads
A way to track an arbitrary number of threads.
MaxInt CurrentFrameStart
What time did the current Frame Start at.
std::vector< MonopolyWorkUnit * >::const_iterator ConstIteratorMonopoly
A const iterator suitable for iterating over the main pool of work units.
This file defines a minimalistic cross-platform thread that the scheduler uses to schedule tasks...
long long MaxInt
A large integer type suitable for compile time math and long term microsecond time keeping...
std::vector< MonopolyWorkUnit * > WorkUnitsMonopolies
A collection of all the monopolies this scheduler must run and keep ownership of. ...
The bulk of the engine components go in this namspace.
unsigned long Whole
Whole is an unsigned integer, it will be at least 32bits in size.
WorkSorter * Sorter
If this pointer is non-zero then the WorkSorter it points at will be used to sort WorkUnits...
ThreadId MainThreadID
For some task it is important to know the ID of the main thread.
The thread ID is a unique identifier for each thread.
DefaultRollingAverage< Whole >::Type FrameTimeLog
A rolling average of Frame times.
DefaultThreadSpecificStorage::Type Resource
The kind of Resource the frame scheduler will use.
std::string String
A datatype used to a series of characters.
Whole CurrentThreadCount
How many threads will this try to execute with in the next frame.
DefaultRollingAverage< Whole >::Type PauseTimeLog
A rolling average of Frame Pause times.