namespace Misaki.HighPerformance.Jobs;
public interface IJobScheduler
{
///
/// Gets the number of worker threads managed by the job scheduler.
///
int WorkerCount
{
get;
}
///
/// Schedules a single job for execution on a specified thread, with an optional dependency on another job.
///
/// The type of the job to execute. Must implement and be unmanaged.
/// The job instance to be executed. The job data will be copied internally.
/// The index of the thread that is preferred to execute the job. This is used to assign thread-specific data. Use -1 to allow any thread to execute the job.
/// A representing the dependencies that must be completed before this job can begin.
/// Use if there are no dependencies.
/// A that can be used to track the completion of the scheduled job.
/// Returns if the job data allocation fails.
JobHandle Schedule(ref readonly T job, int threadIndex, JobHandle dependency)
where T : unmanaged, IJob;
///
/// Schedules a single job for execution on a specified thread without dependency.
///
/// The type of the job to execute. Must implement and be unmanaged.
/// The job instance to be executed. The job data will be copied internally.
/// The index of the thread that is preferred to execute the job. This is used to assign thread-specific data. Use -1 to allow any thread to execute the job.
/// A that can be used to track the completion of the scheduled job.
/// Returns if the job data allocation fails.
JobHandle Schedule(ref readonly T job, int threadIndex)
where T : unmanaged, IJob;
///
/// Schedules a single job for execution on any thread, with an optional dependency on another job.
///
/// The type of the job to execute. Must implement and be unmanaged.
/// The job instance to be executed. The job data will be copied internally.
/// A that can be used to track the completion of the scheduled job.
/// Returns if the job data allocation fails.
JobHandle Schedule(ref readonly T job, JobHandle dependency)
where T : unmanaged, IJob;
///
/// Schedules a single job for execution on any thread without dependency.
///
/// The type of the job to execute. Must implement and be unmanaged.
/// The job instance to be executed. The job data will be copied internally.
/// The index of the thread that is preferred to execute the job. This is used to assign thread-specific data. Use -1 to allow any thread to execute the job.
/// A that can be used to track the completion of the scheduled job.
/// Returns if the job data allocation fails.
JobHandle Schedule(ref readonly T job)
where T : unmanaged, IJob;
///
/// Schedules a parallel job for execution, dividing the workload into batches and distributing it across threads.
///
/// The type of the job to execute. Must implement and be unmanaged.
/// The job instance to be executed. The job data will be copied internally.
/// The total number of iterations to be processed by the job.
/// The number of iterations to include in each batch.
/// The index of the thread that is preferred to execute the job. This is used to assign thread-specific data. Use -1 to allow any thread to execute the job.
/// A representing the dependencies that must be completed before this job can begin.
/// Use if there are no dependencies.
/// A that can be used to track the completion of the scheduled job.
/// Returns if the job data allocation fails.
JobHandle ScheduleParallelFor(ref readonly T job, int totalIteration, int batchSize, int threadIndex, JobHandle dependency)
where T : unmanaged, IJobParallelFor;
///
/// Schedules a parallel job for execution, dividing the workload into batches and distributing it across threads on a specified thread without dependency.
///
/// The type of the job to execute. Must implement and be unmanaged.
/// The job instance to be executed. The job data will be copied internally.
/// The total number of iterations to be processed by the job.
/// The number of iterations to include in each batch.
/// The index of the thread that is preferred to execute the job. This is used to assign thread-specific data. Use -1 to allow any thread to execute the job.
/// A that can be used to track the completion of the scheduled job.
/// Returns if the job data allocation fails.
JobHandle ScheduleParallelFor(ref readonly T job, int totalIteration, int batchSize, int threadIndex)
where T : unmanaged, IJobParallelFor;
///
/// Schedules a parallel job for execution, dividing the workload into batches and distributing it across threads on any thread, with an optional dependency on another job..
///
/// The type of the job to execute. Must implement and be unmanaged.
/// The job instance to be executed. The job data will be copied internally.
/// The total number of iterations to be processed by the job.
/// The number of iterations to include in each batch.
/// The index of the thread that is preferred to execute the job. This is used to assign thread-specific data. Use -1 to allow any thread to execute the job.
/// A that can be used to track the completion of the scheduled job.
/// Returns if the job data allocation fails.
JobHandle ScheduleParallelFor(ref readonly T job, int totalIteration, int batchSize, JobHandle dependency)
where T : unmanaged, IJobParallelFor;
///
/// Schedules a parallel job for execution, dividing the workload into batches and distributing it across threads on any thread without dependency.
///
/// The type of the job to execute. Must implement and be unmanaged.
/// The job instance to be executed. The job data will be copied internally.
/// The total number of iterations to be processed by the job.
/// The number of iterations to include in each batch.
/// The index of the thread that is preferred to execute the job. This is used to assign thread-specific data. Use -1 to allow any thread to execute the job.
/// A that can be used to track the completion of the scheduled job.
/// Returns if the job data allocation fails.
JobHandle ScheduleParallelFor(ref readonly T job, int totalIteration, int batchSize)
where T : unmanaged, IJobParallelFor;
///
/// Schedules a parallel job for execution, dividing the workload into batches and distributing it across threads.
///
/// The type of the job to execute. Must implement and be unmanaged.
/// The job instance to be executed. The job data will be copied internally.
/// The total number of iterations to be processed by the job.
/// The number of iterations to include in each batch.
/// The index of the thread that is preferred to execute the job. This is used to assign thread-specific data. Use -1 to allow any thread to execute the job.
/// A representing the dependencies that must be completed before this job can begin.
/// Use if there are no dependencies.
/// A that can be used to track the completion of the scheduled job.
/// Returns if the job data allocation fails.
JobHandle ScheduleParallel(ref readonly T job, int totalIteration, int batchSize, int threadIndex, JobHandle dependency)
where T : unmanaged, IJobParallel;
///
/// Schedules a parallel job for execution, dividing the workload into batches and distributing it across threads on a specified thread without dependency.
///
/// The type of the job to execute. Must implement and be unmanaged.
/// The job instance to be executed. The job data will be copied internally.
/// The total number of iterations to be processed by the job.
/// The number of iterations to include in each batch.
/// The index of the thread that is preferred to execute the job. This is used to assign thread-specific data. Use -1 to allow any thread to execute the job.
/// A that can be used to track the completion of the scheduled job.
/// Returns if the job data allocation fails.
JobHandle ScheduleParallel(ref readonly T job, int totalIteration, int batchSize, int threadIndex)
where T : unmanaged, IJobParallel;
///
/// Schedules a parallel job for execution, dividing the workload into batches and distributing it across threads on any thread, with an optional dependency on another job..
///
/// The type of the job to execute. Must implement and be unmanaged.
/// The job instance to be executed. The job data will be copied internally.
/// The total number of iterations to be processed by the job.
/// The number of iterations to include in each batch.
/// The index of the thread that is preferred to execute the job. This is used to assign thread-specific data. Use -1 to allow any thread to execute the job.
/// A that can be used to track the completion of the scheduled job.
/// Returns if the job data allocation fails.
JobHandle ScheduleParallel(ref readonly T job, int totalIteration, int batchSize, JobHandle dependency)
where T : unmanaged, IJobParallel;
///
/// Schedules a parallel job for execution, dividing the workload into batches and distributing it across threads on any thread without dependency.
///
/// The type of the job to execute. Must implement and be unmanaged.
/// The job instance to be executed. The job data will be copied internally.
/// The total number of iterations to be processed by the job.
/// The number of iterations to include in each batch.
/// The index of the thread that is preferred to execute the job. This is used to assign thread-specific data. Use -1 to allow any thread to execute the job.
/// A that can be used to track the completion of the scheduled job.
/// Returns if the job data allocation fails.
JobHandle ScheduleParallel(ref readonly T job, int totalIteration, int batchSize)
where T : unmanaged, IJobParallel;
///
/// Combines multiple job dependencies into a single .
///
/// A collection of instances representing the dependencies to combine.
/// A that represents the combined dependencies. The returned handle can be used to ensure
/// that all specified dependencies are completed before proceeding.
JobHandle CombineDependencies(params ReadOnlySpan dependencies);
///
/// Retrieves the current status of a job identified by the specified handle.
///
/// The handle representing the job whose status is to be retrieved. The handle must be valid.
/// The current status of the job as a value.
/// Returns if the handle is invalid or the job does not exist.
JobState GetJobStatus(JobHandle handle);
///
/// Blocks the calling thread until the specified job is completed.
///
/// The handle of the job to wait for.
void Wait(JobHandle handle);
///
/// Blocks the calling thread until all specified job handles have completed.
///
///
/// The collection handles will be reordered in-place to move completed handles to the front.
///
/// A collection of job handles to wait for.
void WaitAll(params Span handles);
///
/// Waits until any of the specified job handles has completed and returns the first completed handle.
///
/// A read-only span containing the job handles to monitor for completion.
/// The first job handle from the provided collection that has completed.
JobHandle WaitAny(params ReadOnlySpan handles);
}