namespace Misaki.HighPerformance.Jobs;
///
/// The state of a job in its lifecycle.
///
public enum JobState
{
///
/// The job is in an invalid state, indicating an error or uninitialized state.
///
Invalid = -1,
///
/// The job has been created but not yet scheduled for execution.
///
Created = 0,
///
/// The job is scheduled and waiting to be executed.
///
Scheduled = 1,
///
/// The job is currently being executed.
///
Running = 2,
///
/// The job has completed execution.
///
Completed = 3
}
internal unsafe struct JobInfo
{
public const int MAX_DEPENDENTS = 8;
// The list of jobs that are waiting for THIS job to complete.
public fixed int dependentsID[MAX_DEPENDENTS]; // The actual list of IDs
public fixed int dependentsGeneration[MAX_DEPENDENTS]; // The actual list of generations
public int dependentCount;
public JobRanges jobRanges;
public void* pJobData;
public JobExecutionFunc pExecutionFunc;
public JobState state;
public int remainingBatches;
public int threadIndex; // The preferred thread index to run this job on, -1 means any thread
public int dependencyCount; // Numbers of jobs that this job depends on, when it reaches 0, the job can be executed
}
internal struct JobRanges
{
public int batchSize;
public int totalIteration;
public int currentIndex;
public static JobRanges Single => new()
{
batchSize = 1,
totalIteration = 1,
currentIndex = 0,
};
}