Spinning Topp Logo BlackTopp Studios
Public Member Functions | Protected Types | Protected Attributes | List of all members
Mezzanine::Threading::AsynchronousFileLoadWorkUnit Class Reference

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>

+ Inheritance diagram for Mezzanine::Threading::AsynchronousFileLoadWorkUnit:
+ Collaboration diagram for Mezzanine::Threading::AsynchronousFileLoadWorkUnit:

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.
RawFileGetFile (const String &FileName) const
 Get a loaded RawFile in linear time. More...
RawFileGetFile (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 iWorkUnitGetDependency (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< StringFilenames
 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.
 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.

Detailed Description

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.

Member Function Documentation

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.

This can leak memory if not used in conjuction with memory management or DeleteLoadedFiles and read the details.
This can fail in horrible ways if called twice without waiting for the first call to finish, use IsWorkDone and read the details.
This returns Starting when loading is successful started and who knows what it returns if it fails, likely a segfault or GPF.

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.

FileNameThe file to retrieve.
A pointer to a RawFile or 0 if it cannot be retrieved for any reason.

Definition at line 128 of file asynchronousfileloadingworkunit.cpp.

RawFile * Mezzanine::Threading::AsynchronousFileLoadWorkUnit::GetFile ( const Whole Index) const

Retrieve a pointer to file contents in constant time.

IndexThe index of the File Name when it was passed into BeginLoading.
This returns a null pointer if the correct RawFile cannot be retrieved, otherwise a pointer to the RawFile with index corresponing to the index of a passed in filename is returned.
Do no call this before IsWorkDone() indicates that the work is Complete. These memory addresses are subject to change until all loading is complete.

Definition at line 141 of file asynchronousfileloadingworkunit.cpp.

RunningState Mezzanine::Threading::AsynchronousFileLoadWorkUnit::IsWorkDone ( )

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.

  • NotStarted - Either BeginLoading has not been called or it has been called and has not progressed to the point where it sets this. Not useful for making logical decisions without knowledge of how many times BeginLoading has been called.
  • Starting - This is returned from BeginLoading is success conditions, and is never returned from this.
  • Running - This means that the loading thread has started but not yet completed.
  • Complete - The loading thread has completed its work, and new loading can definitely begin after the next call to DoWork method.
  • Failed - If somekind of recoverable error occured, this will be returned, there are no guarantees about the state of the loaded files.
    The running state as of the time of this call, though it is subject to immediate thread unsafe change.

Implements Mezzanine::Threading::iAsynchronousWorkUnit.

Definition at line 125 of file asynchronousfileloadingworkunit.cpp.

The documentation for this class was generated from the following files: