A* Pathfinding Project  4.3.5
The A* Pathfinding Project for Unity 3D
JobDependencyTracker Class Reference

Automatic dependency tracking for the Unity Job System. More...

Detailed Description

Automatic dependency tracking for the Unity Job System.

Uses reflection to find the [ReadOnly] and [WriteOnly] attributes on job data struct fields. These are used to automatically figure out dependencies between jobs.

A job that reads from an array depends on the last job that wrote to that array. A job that writes to an array depends on the last job that wrote to the array as well as all jobs that read from the array.

struct ExampleJob : IJob {
public NativeArray<int> someData;
public void Execute () {
// Do something
}
}
void Start () {
var tracker = new JobDependencyTracker();
var data = new NativeArray<int>(100, Allocator.TempJob);
var job1 = new ExampleJob {
someData = data
}.Schedule(tracker);
var job2 = new ExampleJob {
someData = data
}.Schedule(tracker);
// job2 automatically depends on job1 because they both require read/write access to the data array
}
See also
#Pathfinding.Util.IJobExtensions

Classes

struct  JobDispose
 
struct  JobInstance
 
struct  JobRaycastCommandDummy
 
struct  MainThreadWork
 
struct  NativeArraySlot
 

Public Member Functions

void CompleteMainThreadWork ()
 
void DeferDispose< T > (NativeArray< T > data)
 Disposes the native array after all the current jobs are finished with it. More...
 
void DeferFree (GCHandle handle, JobHandle dependsOn)
 Frees the GCHandle when the JobDependencyTracker is disposed. More...
 
void ForceLinearDependencies ()
 Disable dependency tracking and just run jobs one after the other. More...
 
NativeArray< T > NewNativeArray< T > (int length, Allocator allocator, NativeArrayOptions options=NativeArrayOptions.ClearMemory)
 
void RunMainThreadWork ()
 
JobHandle ScheduleBatch (NativeArray< UnityEngine.RaycastCommand > commands, NativeArray< UnityEngine.RaycastHit > results, int minCommandsPerJob)
 Schedules a raycast batch command. More...
 

Package Functions

void AddMainThreadWork (IJob job, ManualResetEvent doneEvent, ManualResetEvent dependenciesDoneEvent, JobHandle dependsOn)
 
void JobReadsFrom (JobHandle job, long nativeArrayHash, int jobHash)
 
void JobWritesTo (JobHandle job, long nativeArrayHash, int jobHash)
 

Package Attributes

List< NativeArraySlotslots = ListPool<NativeArraySlot>.Claim()
 

Properties

JobHandle AllWritesDependency [get]
 JobHandle that represents a dependency for all jobs. More...
 
bool forceLinearDependencies [get, private set]
 

Private Member Functions

void Dispose ()
 Diposes this tracker. More...
 
void IAstarPooledObject. OnEnterPool ()
 

Private Attributes

NativeArrayArena arena
 
List< GCHandle > gcHandlesToFree
 
List< MainThreadWorkmainThreadWork = ListPool<MainThreadWork>.Claim()
 
NativeList< JobHandle > temporaryJobs
 

Member Function Documentation

◆ AddMainThreadWork()

void AddMainThreadWork ( IJob  job,
ManualResetEvent  doneEvent,
ManualResetEvent  dependenciesDoneEvent,
JobHandle  dependsOn 
)
package

◆ CompleteMainThreadWork()

void CompleteMainThreadWork ( )

◆ DeferDispose< T >()

void DeferDispose< T > ( NativeArray< T >  data)

Disposes the native array after all the current jobs are finished with it.

Type Constraints
T :struct 

◆ DeferFree()

void DeferFree ( GCHandle  handle,
JobHandle  dependsOn 
)

Frees the GCHandle when the JobDependencyTracker is disposed.

◆ Dispose()

void Dispose ( )
private

Diposes this tracker.

This will pool all used lists which makes the GC happy.

Note
It is necessary to call this method to avoid memory leaks if you are using the DeferDispose method. But it's a good thing to do otherwise as well. It is automatically called if you are using the ObjectPool<T>.Release method.

◆ ForceLinearDependencies()

void ForceLinearDependencies ( )

Disable dependency tracking and just run jobs one after the other.

This may be faster in some cases since dependency tracking has some overhead.

◆ JobReadsFrom()

void JobReadsFrom ( JobHandle  job,
long  nativeArrayHash,
int  jobHash 
)
package

◆ JobWritesTo()

void JobWritesTo ( JobHandle  job,
long  nativeArrayHash,
int  jobHash 
)
package

◆ NewNativeArray< T >()

NativeArray<T> NewNativeArray< T > ( int  length,
Allocator  allocator,
NativeArrayOptions  options = NativeArrayOptions.ClearMemory 
)
Type Constraints
T :struct 

◆ OnEnterPool()

void IAstarPooledObject. OnEnterPool ( )
private

Implements IAstarPooledObject.

◆ RunMainThreadWork()

void RunMainThreadWork ( )

◆ ScheduleBatch()

JobHandle ScheduleBatch ( NativeArray< UnityEngine.RaycastCommand >  commands,
NativeArray< UnityEngine.RaycastHit >  results,
int  minCommandsPerJob 
)

Schedules a raycast batch command.

Like RaycastCommand.ScheduleBatch, but dependencies are tracked automatically.

Member Data Documentation

◆ arena

NativeArrayArena arena
private

◆ gcHandlesToFree

List<GCHandle> gcHandlesToFree
private

◆ mainThreadWork

List<MainThreadWork> mainThreadWork = ListPool<MainThreadWork>.Claim()
private

◆ slots

List<NativeArraySlot> slots = ListPool<NativeArraySlot>.Claim()
package

◆ temporaryJobs

NativeList<JobHandle> temporaryJobs
private

Property Documentation

◆ AllWritesDependency

JobHandle AllWritesDependency
get

JobHandle that represents a dependency for all jobs.

All native arrays that are written (and have been tracked by this tracker) to will have their final results in them when the returned job handle is complete.

◆ forceLinearDependencies

bool forceLinearDependencies
getprivate set

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