Files
Misaki.HighPerformance/Misaki.HighPerformance.Test/Jobs/JobDispatchingJob.cs
Misaki 8b7f773d29 feat(JobScheduler): improve dependency handling logic
Updated `JobScheduler` to enhance dependency tracking by counting valid dependencies upfront and dynamically adjusting counts using `Interlocked` operations. Improved job enqueueing logic to ensure jobs are only enqueued when all dependencies are met.

Replaced `Interlocked.Increment` with `Interlocked.Add` for batch updates to `_totalJobCount`, improving performance. Adjusted `VirtualStack` cleanup to use the correct size variable for memory deallocation.

Simplified `JobDispatchingJob` API by removing `ctx.ThreadIndex` parameter. Updated `TestJobSystem` to pass job handles as dependencies for proper execution order.

Incremented assembly version to 1.5.9 to reflect these changes.
2026-04-12 22:09:28 +09:00

35 lines
959 B
C#

using Misaki.HighPerformance.Jobs;
using Misaki.HighPerformance.LowLevel.Collections;
namespace Misaki.HighPerformance.Test.Jobs;
internal struct JobDispatchingJob : IJobParallelFor
{
public UnsafeArray<UnsafeArray<int>> data;
public UnsafeList<JobHandle>.ParallelWriter handles;
private struct InnerJob : IJobParallelFor
{
public UnsafeArray<int> data;
public void Execute(int loopIndex, ref readonly JobExecutionContext ctx)
{
ref var value = ref data[loopIndex];
value *= 2;
}
}
public void Execute(int loopIndex, ref readonly JobExecutionContext ctx)
{
if (loopIndex % 2 == 0)
{
var innerJob = new InnerJob
{
data = data[loopIndex]
};
var handle = ctx.JobScheduler.ScheduleParallelFor(in innerJob, data[loopIndex].Length, 64);
handles.AddNoResize(handle);
}
}
}