Refactor job system and update project configuration
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.
This commit is contained in:
@@ -1,80 +1,38 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
namespace Misaki.HighPerformance.Jobs;
|
||||
|
||||
namespace Misaki.HighPerformance.Jobs;
|
||||
|
||||
/// <summary>
|
||||
/// A handle that represents a scheduled job and can be used to manage dependencies and wait for completion.
|
||||
/// JobHandle is designed to be a lightweight value type to avoid allocations.
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public readonly struct JobHandle : IEquatable<JobHandle>
|
||||
{
|
||||
internal readonly ulong _id;
|
||||
internal readonly int _version;
|
||||
internal readonly int _id;
|
||||
internal readonly int _generation;
|
||||
|
||||
internal JobHandle(ulong id, int version)
|
||||
public static JobHandle Invalid => new(-1, -1);
|
||||
|
||||
public bool IsValid => this != Invalid;
|
||||
|
||||
internal JobHandle(int id, int generation)
|
||||
{
|
||||
_id = id;
|
||||
_version = version;
|
||||
_generation = generation;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A completed job handle that can be used as a dependency that is already satisfied.
|
||||
/// </summary>
|
||||
public static JobHandle Completed => new(0, 0);
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether this job handle represents a completed job.
|
||||
/// </summary>
|
||||
public bool IsCompleted => _id == 0 || JobScheduler.IsCompleted(this);
|
||||
|
||||
/// <summary>
|
||||
/// Blocks the calling thread until the job completes.
|
||||
/// </summary>
|
||||
public void Complete()
|
||||
{
|
||||
if (_id != 0)
|
||||
{
|
||||
JobScheduler.Complete(this);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Combines multiple job handles into a single dependency.
|
||||
/// The resulting handle will be complete when all input handles are complete.
|
||||
/// </summary>
|
||||
/// <param name="dependencies">The job handles to combine.</param>
|
||||
/// <returns>A new job handle that depends on all input handles.</returns>
|
||||
public static JobHandle CombineDependencies(params ReadOnlySpan<JobHandle> dependencies)
|
||||
{
|
||||
if (dependencies.Length == 0)
|
||||
{
|
||||
return Completed;
|
||||
}
|
||||
|
||||
if (dependencies.Length == 1)
|
||||
{
|
||||
return dependencies[0];
|
||||
}
|
||||
|
||||
return JobScheduler.CombineDependencies(dependencies);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool Equals(JobHandle other)
|
||||
{
|
||||
return _id == other._id && _version == other._version;
|
||||
return _id == other._id && _generation == other._generation;
|
||||
}
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
return obj is JobHandle other && Equals(other);
|
||||
return obj is JobHandle handle && Equals(handle);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(_id, _version);
|
||||
return HashCode.Combine(_id, _generation);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return IsValid ? $"JobHandle({_id}, {_generation})" : "JobHandle(Invalid)";
|
||||
}
|
||||
|
||||
public static bool operator ==(JobHandle left, JobHandle right)
|
||||
@@ -84,11 +42,6 @@ public readonly struct JobHandle : IEquatable<JobHandle>
|
||||
|
||||
public static bool operator !=(JobHandle left, JobHandle right)
|
||||
{
|
||||
return !left.Equals(right);
|
||||
return !(left == right);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return _id == 0 ? "JobHandle(Completed)" : $"JobHandle(ID:{_id}, Version:{_version})";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user