This is intended to load files asynchronously and continue doing so whether or not other the FrameScheduler is running or paused. More...
#include <asynchronousfileloadingworkunit.h>
Public Member Functions | |
AsynchronousFileLoadWorkUnit () | |
Default constructor. | |
virtual | ~AsynchronousFileLoadWorkUnit () |
Destructor, deletes all loaded files. | |
RunningState | BeginLoading (const std::vector< String > &Filenames_) |
Begin loading a list of files based on their names. More... | |
void | DeleteLoadedFiles () |
This deletes all the loaded files from the last call of BeginLoading . | |
virtual void | DoWork (DefaultThreadSpecificStorage::Type &) |
This checks if Asynchronous loading thread has completed and if so it cleans up that threads' resources. | |
RawFile * | GetFile (const String &FileName) const |
Get a loaded RawFile in linear time. More... | |
RawFile * | GetFile (const Whole &Index) const |
Retrieve a pointer to file contents in constant time. More... | |
virtual RunningState | IsWorkDone () |
Get the RunningState of the file loading. More... | |
Public Member Functions inherited from Mezzanine::Threading::DefaultWorkUnit | |
DefaultWorkUnit () | |
Simple constructor. | |
virtual | ~DefaultWorkUnit () |
Virtual destructor, doesn't actually do much. | |
virtual void | AddDependency (iWorkUnit *NewDependency) |
Force this WorkUnit to Start after another has completed. More... | |
virtual void | ClearDependencies () |
Drop any information about what work units this one depends on. | |
virtual iWorkUnit * | GetDependency (Whole Index) const |
This is used to iterate of all the dependencies. More... | |
virtual Whole | GetDependencyCount () const |
How many other WorkUnits does this one depend on? More... | |
virtual Whole | GetDependentCount (FrameScheduler &SchedulerToCount) |
This returns the count workunits that depend on this work unit. More... | |
virtual Whole | GetImmediateDependencyCount () const |
Get the amount of dependencies that directly count on this for access purposes. More... | |
virtual Whole | GetPerformance () const |
Get the internal rolling average for querying. More... | |
virtual RollingAverage< Whole > & | GetPerformanceLog () |
Get the internal rolling average for querying. More... | |
virtual RunningState | GetRunningState () const |
Retrieves the current RunningState of the thread. More... | |
virtual WorkUnitKey | GetSortingKey (FrameScheduler &SchedulerToCount) |
Get the sorting metadata. More... | |
virtual bool | IsEveryDependencyComplete () |
Check if this WorkUnit could concievably run right now. More... | |
virtual void | operator() (DefaultThreadSpecificStorage::Type &CurrentThreadStorage) |
This does everything required to track metadata and log work. More... | |
virtual void | PrepareForNextFrame () |
This resets the running state and takes any further action required to use the WorkUnit again. | |
virtual void | RemoveDependency (iWorkUnit *RemoveDependency) |
Remove a dependency. More... | |
virtual RunningState | TakeOwnerShip () |
Attempts to atomically start the work unit in the current thread. More... | |
Public Member Functions inherited from Mezzanine::Threading::iWorkUnit | |
virtual | ~iWorkUnit () |
Virtual destructor. | |
Protected Types | |
typedef std::vector< RawFile * > | RawFileContainer |
Used to make referencing the the type of FilesRaw easier. | |
Protected Attributes | |
std::vector< String > | Filenames |
The names of the files this batch of loading will retrieve. | |
RawFileContainer | FilesRaw |
The contents of the files once they have been loaded. No partial files will exists here, either the whole file is added or nothing is added. | |
Thread * | LoadingThread |
This is either 0 or the other thread that is loading. | |
Int32 | Status |
This stores the current RunningState. | |
Protected Attributes inherited from Mezzanine::Threading::DefaultWorkUnit | |
Int32 | CurrentRunningState |
This controls do work with this after it has. | |
std::vector< iWorkUnit * > | Dependencies |
A collection of of workunits that must be complete before this one can start. | |
DefaultRollingAverage< Whole >::Type | PerformanceLog |
A rolling average of execution times. | |
This is intended to load files asynchronously and continue doing so whether or not other the FrameScheduler is running or paused.
The goal is to trigger lower level mechanisms to use DMA to load directly without CPU intervention. In some operating systems this is handled in the standard library, and in others special mechanisms must be used to make this happen. The current state of this allows testing to determine how good automatic mechanisms work.
Definition at line 100 of file asynchronousfileloadingworkunit.h.
RunningState Mezzanine::Threading::AsynchronousFileLoadWorkUnit::BeginLoading | ( | const std::vector< String > & | Filenames_ | ) |
Begin loading a list of files based on their names.
Filenames_ | A vector of Strings that correspond to either relative or absolute filenames that will be loaded. |
When the file is loaded its contents are placed in a RawFile and can be retrieved with GetFile or GetFile member functions.
This starts by clearing the previous list of loaded files. If that list has not been deleted then this will cause a memory leak. Use DeleteLoadedFiles to clear this list or copy all the pointers elsewhere before calling this and delete them manually at your convience. When this work unit is destroyed it deletes any loaded files from the last call of this method.
If this is called while it is loading files the behavior is undefined, most likely it will crash or fail silently, either way no good can come from it. Use IsWorkDone to see if the work is Complete. If the work is complete then this can be called after any call to this class's DoWork member function.
Definition at line 100 of file asynchronousfileloadingworkunit.cpp.
RawFile * Mezzanine::Threading::AsynchronousFileLoadWorkUnit::GetFile | ( | const String & | FileName | ) | const |
Get a loaded RawFile in linear time.
This searches the list of files names to determine the index of the filename then calls GetFile.
FileName | The file to retrieve. |
Definition at line 128 of file asynchronousfileloadingworkunit.cpp.
Retrieve a pointer to file contents in constant time.
Index | The index of the File Name when it was passed into BeginLoading. |
Definition at line 141 of file asynchronousfileloadingworkunit.cpp.
|
virtual |
Get the RunningState of the file loading.
This can return any RunningState and the meaning applies to the current state of the files being loaded.
Implements Mezzanine::Threading::iAsynchronousWorkUnit.
Definition at line 125 of file asynchronousfileloadingworkunit.cpp.