Added: - Added `JobExecutor.cs` for job execution management. - Added `JobInfo.cs` to hold job execution information. - Added `TestJobSystem.cs` for unit tests of the job system. - Added `TestJobs.cs` for additional job implementation tests. - Added `WorkerThread.cs` to manage worker threads for jobs. Changed: - Changed `AssemblyInfo.cs.cs` to include a global using directive for `unsafe JobExecuteFunc`. - Changed `IJob.cs` to include an overload of the `Execute` method with a `threadIndex` parameter. - Changed `JobHandle.cs` to include an `IsValid` property and updated internal structure. - Changed `JobScheduler.cs` to improve job scheduling and management. - Changed `JobsUtility.cs` to enhance job management functions. - Changed `MemoryBlock.cs` to reference the heap from which memory was allocated. - Changed `ParallelNoiseBenchmark.cs` to include benchmarks for the job system. - Changed `Program.cs` to execute benchmarks instead of previous test code. Removed: - Removed `.gitignore` entries for default ignored files. - Removed `JobBase.cs` to shift from structs to classes for jobs. - Removed `JobExtensions.cs` indicating a change in job scheduling. - Removed `JobStruct.cs` indicating a change in job structure. - Removed `encodings.xml`, `indexLayout.xml`, and `vcs.xml` files to simplify project configuration. - Removed fields from `JobData.cs` to simplify the job data structure. - Removed `TestJobSystem.csproj` entries related to old project structure.
54 lines
1.5 KiB
C#
54 lines
1.5 KiB
C#
namespace Misaki.HighPerformance.Jobs;
|
|
|
|
internal unsafe static class JobExecutor
|
|
{
|
|
public static bool Execute<T>(void* pJobData, ref JobRanges jobRanges, ref int remainingBatches, int threadIndex)
|
|
where T : unmanaged, IJob
|
|
{
|
|
var pJob = (T*)pJobData;
|
|
pJob->Execute(threadIndex);
|
|
|
|
return Interlocked.Decrement(ref remainingBatches) == 0;
|
|
}
|
|
|
|
private static bool GetWorkerStealingRange(ref JobRanges jobRanges, out int start, out int end)
|
|
{
|
|
start = Interlocked.Add(ref jobRanges.currentIndex, jobRanges.batchSize) - jobRanges.batchSize;
|
|
|
|
if (start >= jobRanges.totalIteration)
|
|
{
|
|
end = start;
|
|
return false;
|
|
}
|
|
|
|
end = Math.Min(start + jobRanges.batchSize, jobRanges.totalIteration);
|
|
return true;
|
|
}
|
|
|
|
public static bool ExecuteParallel<T>(void* pJobData, ref JobRanges jobRanges, ref int remainingBatches, int threadIndex)
|
|
where T : unmanaged, IJobParallelFor
|
|
{
|
|
var pJob = (T*)pJobData;
|
|
var wasTheLastBatch = false;
|
|
|
|
while (true)
|
|
{
|
|
if (!GetWorkerStealingRange(ref jobRanges, out var start, out var end))
|
|
{
|
|
break;
|
|
}
|
|
|
|
for (var i = start; i < end; i++)
|
|
{
|
|
pJob->Execute(i, threadIndex);
|
|
}
|
|
|
|
if (Interlocked.Decrement(ref remainingBatches) == 0)
|
|
{
|
|
wasTheLastBatch = true;
|
|
}
|
|
}
|
|
|
|
return wasTheLastBatch;
|
|
}
|
|
} |