Hydrogen Framework  1.3.1
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events
Hydrogen.Threading.JobBase Class Referenceabstract
+ Inheritance diagram for Hydrogen.Threading.JobBase:

Public Member Functions

virtual bool Check ()
 Checks if the Job is done, and facilitates calling OnFinished when completed. More...
 
abstract void Start (bool backgroundThread, System.Threading.ThreadPriority priority)
 Start the work process, should probably send the Run function to the thread! More...
 

Protected Member Functions

virtual void Abort ()
 Abort the Job (as best we can). More...
 
virtual void OnFinished ()
 Called once by Check when the Job has finished. More...
 
virtual void Run (object state)
 The launcher of the ThreadedFunction, used to handle the state as well. More...
 
virtual void ThreadedFunction ()
 The work horse function that MUST BE THREAD SAFE. Do not touch the Unity API! It will cause an exception if you do, and things will act like a 4 year old having a tantrum. Debugging should be handled via System.Console and you should be aware that exceptions will not show up in Unity if they happen on the thread; therefore you will never know if its broken so test your code outside of the threading first, or have copius amounts of debugging implemented. More...
 

Properties

bool IsBusy [get, set]
 Is the Job busy working? More...
 
bool IsDone [get, set]
 Is the Job done? More...
 
bool FiredOnFinished [get, set]
 Has the OnFinished been called yet? More...
 

Detailed Description

The base for all classes which want to extend the behaviour of a Job.

Definition at line 34 of file JobBase.cs.

Member Function Documentation

virtual void Hydrogen.Threading.JobBase.Abort ( )
protectedvirtual

Abort the Job (as best we can).

Reimplemented in Hydrogen.Threading.ThreadedJob.

Definition at line 134 of file JobBase.cs.

135  {
136  IsBusy = false;
137  IsDone = false;
138  FiredOnFinished = true;
139  }
bool FiredOnFinished
Has the OnFinished been called yet?
Definition: JobBase.cs:95
bool IsDone
Is the Job done?
Definition: JobBase.cs:76
bool IsBusy
Is the Job busy working?
Definition: JobBase.cs:57
virtual bool Hydrogen.Threading.JobBase.Check ( )
virtual

Checks if the Job is done, and facilitates calling OnFinished when completed.

Definition at line 113 of file JobBase.cs.

114  {
115  if (IsDone) {
116 
117  // Only fire off our OnFinished if we haven't before.
118  if (!FiredOnFinished) {
119 
120  // Fireoff our Finish Code
121  OnFinished ();
122 
123  // Stop From Firing Again
124  FiredOnFinished = true;
125  }
126  return true;
127  }
128  return false;
129  }
bool FiredOnFinished
Has the OnFinished been called yet?
Definition: JobBase.cs:95
virtual void OnFinished()
Called once by Check when the Job has finished.
Definition: JobBase.cs:145
bool IsDone
Is the Job done?
Definition: JobBase.cs:76
virtual void Hydrogen.Threading.JobBase.OnFinished ( )
protectedvirtual

Called once by Check when the Job has finished.

Can use Unity API.

Reimplemented in Hydrogen.Threading.Jobs.MeshCombiner.

Definition at line 145 of file JobBase.cs.

146  {
147  }
virtual void Hydrogen.Threading.JobBase.Run ( object  state)
protectedvirtual

The launcher of the ThreadedFunction, used to handle the state as well.

Parameters
stateIrrelevent / Not Used. Required for the ThreadPool to be used.

Definition at line 153 of file JobBase.cs.

154  {
155  IsBusy = true;
156 
157  // I guess we can't be done now can we?
158  IsDone = false;
159 
160  FiredOnFinished = false;
161 
162  // Execute our threaded function
163  ThreadedFunction ();
164 
165  // Not busy anymore
166  IsBusy = false;
167 
168  // Yup we are now done.
169  IsDone = true;
170  }
bool FiredOnFinished
Has the OnFinished been called yet?
Definition: JobBase.cs:95
bool IsDone
Is the Job done?
Definition: JobBase.cs:76
bool IsBusy
Is the Job busy working?
Definition: JobBase.cs:57
virtual void ThreadedFunction()
The work horse function that MUST BE THREAD SAFE. Do not touch the Unity API! It will cause an except...
Definition: JobBase.cs:187
abstract void Hydrogen.Threading.JobBase.Start ( bool  backgroundThread,
System.Threading.ThreadPriority  priority 
)
pure virtual

Start the work process, should probably send the Run function to the thread!

Parameters
backgroundThreadIf set to true the thread will be set to background.
priorityThe thread priority.

Implemented in Hydrogen.Threading.ThreadedJob, and Hydrogen.Threading.ThreadPoolJob.

virtual void Hydrogen.Threading.JobBase.ThreadedFunction ( )
protectedvirtual

The work horse function that MUST BE THREAD SAFE. Do not touch the Unity API! It will cause an exception if you do, and things will act like a 4 year old having a tantrum. Debugging should be handled via System.Console and you should be aware that exceptions will not show up in Unity if they happen on the thread; therefore you will never know if its broken so test your code outside of the threading first, or have copius amounts of debugging implemented.

Threading: Because when it works, its awesome.

Reimplemented in Hydrogen.Threading.Jobs.MeshCombiner.

Definition at line 187 of file JobBase.cs.

188  {
189 
190  }

Property Documentation

bool Hydrogen.Threading.JobBase.FiredOnFinished
getset

Has the OnFinished been called yet?

true if it has; otherwise, false.

Definition at line 95 of file JobBase.cs.

bool Hydrogen.Threading.JobBase.IsBusy
getset

Is the Job busy working?

true if is; otherwise, false.

Definition at line 57 of file JobBase.cs.

bool Hydrogen.Threading.JobBase.IsDone
getset

Is the Job done?

true if is; otherwise, false.

Definition at line 76 of file JobBase.cs.