Shkyera Engine
Easy to use, game engine for Python
Loading...
Searching...
No Matches
shkyera::JobSystem Class Reference

#include <JobSystem.hpp>

Classes

struct  Job
 
class  JobBuilder
 

Public Member Functions

JobExecutor pull ()
 
void wait ()
 

Static Public Member Functions

static JobSystemgetInstance ()
 

Private Types

enum class  JobStatus : uint8_t { PENDING , RUNNING , DONE }
 

Private Member Functions

 JobSystem ()=default
 
JobHandle submit (Job &&job)
 
bool isScheduled (JobHandle handle) const
 
std::optional< JobHandlegetJob ()
 
void markJobAsDone (JobHandle handle)
 

Private Attributes

std::mutex _mutex
 
std::condition_variable _cv
 
JobHandle _nextJobHandle
 
TypeSet _resourcesRead
 
TypeSet _resourcesWritten
 
SparseSet< Job_jobs
 

Friends

class SparseSet< Job >
 

Detailed Description

Singleton class managing job scheduling and execution. Provides a thread-safe job system for parallel task execution with resource dependencies. Jobs can be configured with dependencies, resource requirements, and thread affinity.

Member Enumeration Documentation

◆ JobStatus

Enumerator
PENDING 
RUNNING 
DONE 

Constructor & Destructor Documentation

◆ JobSystem()

shkyera::JobSystem::JobSystem ( )
privatedefault

Member Function Documentation

◆ getInstance()

JobSystem & shkyera::JobSystem::getInstance ( )
static

Gets the singleton instance of the job system. This is the only way to access the job system instance.

Returns
Reference to the job system instance

◆ getJob()

std::optional< JobHandle > shkyera::JobSystem::getJob ( )
private

Gets the next available job that can be executed. A job is available if all its dependencies are satisfied and its resource requirements don't conflict with currently running jobs.

Returns
Optional containing the next job handle if available

◆ isScheduled()

bool shkyera::JobSystem::isScheduled ( JobHandle  handle) const
private

Checks if a job is currently scheduled in the system. A job is considered scheduled if it has been submitted and the user did not wait() for all jobs to complete.

Parameters
handleThe job handle to check
Returns
true if the job is scheduled, false otherwise

◆ markJobAsDone()

void shkyera::JobSystem::markJobAsDone ( JobHandle  handle)
private

Marks a job as completed and updates resource states. This will release any resources that were being used by the job.

Parameters
handleThe handle of the completed job

◆ pull()

JobExecutor shkyera::JobSystem::pull ( )

Pulls the next available job for execution.

Returns
Executor function for the next available job

◆ submit()

JobHandle shkyera::JobSystem::submit ( Job &&  job)
private

Submits a job to the system for execution. The job will be scheduled based on its dependencies and resource requirements.

Parameters
jobThe job to be submitted
Returns
Handle to the submitted job

◆ wait()

void shkyera::JobSystem::wait ( )

Waits for all scheduled jobs to complete. This method blocks until all jobs in the system have finished execution.

Friends And Related Symbol Documentation

◆ SparseSet< Job >

Member Data Documentation

◆ _cv

std::condition_variable shkyera::JobSystem::_cv
private

◆ _jobs

SparseSet<Job> shkyera::JobSystem::_jobs
private

◆ _mutex

std::mutex shkyera::JobSystem::_mutex
private

◆ _nextJobHandle

JobHandle shkyera::JobSystem::_nextJobHandle
private

◆ _resourcesRead

TypeSet shkyera::JobSystem::_resourcesRead
private

◆ _resourcesWritten

TypeSet shkyera::JobSystem::_resourcesWritten
private

The documentation for this class was generated from the following files: