MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Namespaces | Classes | Typedefs | Enumerations | Functions | Variables
Mezzanine::Threading Namespace Reference

This is where game specific threading algorithms and a minimalistic subset of the std threading library a held. More...

Namespaces

 this_thread
 A partial implementation of std::thread::this_thread.
 

Classes

struct  _thread_start_info
 Information to pass to the new thread (what to run). More...
 
class  AsynchronousFileLoadWorkUnit
 This is intended to load files asynchronously and continue doing so whether or not other the FrameScheduler is running or paused. More...
 
class  Barrier
 A synchronization primitive that causes a predefined number of threads to all wait before continuing. More...
 
struct  DefaultThreadSpecificStorage
 Use this to change the default resource type. More...
 
class  DefaultWorkUnit
 Default implementation of WorkUnit. This represents on piece of work through time. More...
 
class  DoubleBufferedResource
 A thread specific resource that uses double buffering to avoid multithreaded synchronization mechanisms. More...
 
class  FrameScheduler
 This is central object in this algorithm, it is responsible for spawning threads and managing the order that work units are executed. More...
 
class  iAsynchronousWorkUnit
 The interface for a WorkUnit that will keep running when the rest of the scheduler is paused. More...
 
class  iWorkUnit
 Interface of a WorkUnit. This represents on piece of work through time. More...
 
class  lock_guard
 Lock guard class. More...
 
class  LogAggregator
 Gather all the thread specific logs and commit them to the main log. More...
 
class  MonopolyWorkUnit
 A kind of workunit given exclusive runtime so it can consume time on multiple threads. More...
 
class  Mutex
 A cross-platform abstraction of the OS's mutex. More...
 
class  RawFile
 A simple in memory representation of a file. More...
 
class  ReadOnlyLockGuard
 Read only lock guard. More...
 
class  ReadWriteLockGuard
 ReadWrite lock guard. More...
 
class  ReadWriteSpinLock
 A mutex like construct that supports multiple readsingle writer semantics and never makes a system call and uses CPU instructions instead. More...
 
class  ScopedTimer
 Used to time from this objects creation to its destruction. More...
 
class  SpinLock
 A mutex like construct that never makes a system call and uses CPU instructions instead. More...
 
class  Thread
 A small wrapper around the system thread. More...
 
class  ThreadId
 The thread ID is a unique identifier for each thread. More...
 
class  ThreadSpecificStorage
 A thread specific collection of double-buffered and algorithm specific resources. More...
 
class  WorkSorter
 Sorts all of the WorkUnits in the FrameScheduler. More...
 
class  WorkUnitKey
 Stores data about a single work unit so that it can easily be sorted. More...
 

Typedefs

typedef DoubleBufferedResource
< std::stringstream > 
DoubleBufferedLogger
 A better default name for the Default Logger instance.
 

Enumerations

enum  RunningState {
  NotStarted =0, Starting =1, Running =2, Complete =3,
  Failed =4
}
 Used to track whether a thread has started, completed, etc... More...
 

Functions

Int32 AtomicAdd (Int32 *VariableToChange, Int32 Value)
 Increments a value in a way guaranteed to not lose any atomic increments. More...
 
Int32 AtomicCompareAndSwap32 (Int32 *VariableToChange, const Int32 &OldValue, const Int32 &NewValue)
 Atomically Compares And Swaps a 32 bit value. More...
 
 catch (...)
 
lock_guard< Mutexguard (ti->mThread->mDataMutex)
 
void ThreadLoading (void *WU)
 An Internal helper function for the AsynchronousFileLoadWorkUnit. This is the function that AsynchronousFileLoadWorkUnit instances will use to load data. More...
 

Variables

static const Whole DBRInvalid = 10000000
 Double buffered resources are identified by a Whole which is their type ID, This number identifies an invalid entry.
 
static const Whole DBRLogger = 0
 Double buffered resources are identified by a Whole which is their type ID, This number identifies logging.
 
static const Whole DBRUser = 1
 Double buffered resources are identified by a Whole which is their type ID, All System Type IDs will be less than this amount. More...
 
ti mThread mNotAThread = true
 
 return
 
delete ti
 
 try
 

Detailed Description

This is where game specific threading algorithms and a minimalistic subset of the std threading library a held.

This implements all of the multithreaded algorithms from BlackTopp Studios, parts of std::thread, std::this_thread, std:: mutex, and maybe a few others. In general only the specialized gaming algorithms store here are intended to be used in game code.

Enumeration Type Documentation

Used to track whether a thread has started, completed, etc...

Enumerator
NotStarted 

Task is not yet started this frame, this can change without notice.

Starting 

Only used when a thread successfully attempts to gain ownership of a task, or some other tasks successfully starts.

Running 

Task is running when the value was check, it could become Complete or Failed with no notice.

Complete 

Thread has completed all work this from frame, will not change until this frame ends.

Failed 

Indicates an abnormal termination of a Workunit or other failure, Likely the whole application will need to stop.

Definition at line 54 of file threadingenumerations.h.

Function Documentation

Int32 MEZZ_LIB Mezzanine::Threading::AtomicAdd ( Int32 *  VariableToChange,
Int32  Value 
)

Increments a value in a way guaranteed to not lose any atomic increments.

Parameters
VariableToChangeA pointer to the 32 bit integer to increment by the amount specified.
ValueThe amount to increment the VariableToChange by.
Note
This very specific semantics of this function are useless in most scripting so it is not included in Lua and other scripting languages.
Returns
The newly incremented value. This is not always *VariableToChange+Value. If another thread attempted and atomic operation on this at the same time the result could be the new value pointed to by VariableToChange plus Value.

Definition at line 73 of file atomicoperations.cpp.

Int32 MEZZ_LIB Mezzanine::Threading::AtomicCompareAndSwap32 ( Int32 *  VariableToChange,
const Int32 &  OldValue,
const Int32 &  NewValue 
)

Atomically Compares And Swaps a 32 bit value.

In such a way that this cannot be interupted by another thread this performs a number of steps. First, it compares the dereferenced value VariableToChange to OldValue. Then if they match it writes NewValue to the memory location VariableToChange points to. If they did not match, no work is performed except the dereferencing. In either case since VariableToChange has been derefenced the value stored before any exchange that might have occured is returned.

Parameters
VariableToChangeA pointer to the value to compare and if it matches OldValue Atomically change.
OldValuewhat is expected to be at the other end of VariableToChange.
NewValueThe value to be written to VariableToChange if at the time the actual CPU instruction is executed OldValue Matches *VariableToChange.
Note
This very specific semantics of this function are useless in most scripting so it is not included in Lua and other scripting languages.
Returns
This always returns the value that was pointed to by VariableToChange immediately before this call.

Definition at line 54 of file atomicoperations.cpp.

void Mezzanine::Threading::ThreadLoading ( void *  WU)

An Internal helper function for the AsynchronousFileLoadWorkUnit. This is the function that AsynchronousFileLoadWorkUnit instances will use to load data.

There is a 1 to 1 relationship between this function and its associated AsynchronousFileLoadWorkUnit. This is the function run in another thread to allow loading asynchrously.

Parameters
WUA pointer to the AsynchronousFileLoadWorkUnit that is passed to the asynchronous thread to be used as metadata.

Definition at line 56 of file asynchronousfileloadingworkunit.cpp.

Variable Documentation

const Whole Mezzanine::Threading::DBRUser = 1
static

Double buffered resources are identified by a Whole which is their type ID, All System Type IDs will be less than this amount.

Note
Do not use the value of this directly, it is subject to change. In code using this, use:
const static whole FreshDBRType = BDRUser+YourValue;

Definition at line 62 of file doublebufferedresource.h.

Mezzanine::Threading::try
Initial value:
{
ti->mFunction(ti->mArg)

Definition at line 137 of file thread.cpp.