Jobrocket
jobrocket::Scheduler Class Reference

#include <Scheduler.hpp>

Overview

A Scheduler takes pre-allocated jobs and schedules them onto worker threads owned by the internal scheduler

Public Member Functions

 Scheduler ()=default
 
 ~Scheduler ()
 Calls shutdown before destruction. More...
 
uint32_t auto_worker_count_value ()
 Gets the number of threads created when auto_worker_count is used on startup. More...
 
void startup (int32_t num_threads, int32_t num_main_threads)
 
void shutdown ()
 
void schedule_job (Job *job)
 
void register_main_thread ()
 
Workerthread_local_worker ()
 Gets a pointer to the current threads associated worker. More...
 
uint32_t core_count ()
 Gets the number of real CPU cores on the current platform. More...
 
uint32_t hardware_thread_count ()
 Gets the number of threads available on the current platform including hyperthreads. More...
 
uint32_t num_workers ()
 Gets the number of workers active within the scheduler. More...
 
uint32_t num_main_threads ()
 Gets the max number of main threads the scheduler can support. More...
 

Static Public Attributes

static constexpr int32_t auto_thread_count = -1
 Flag for letting the scheduler decide how many worker threads to create. More...
 
static constexpr uint32_t job_capacity_per_worker = 4096
 

Constructor & Destructor Documentation

◆ Scheduler()

jobrocket::Scheduler::Scheduler ( )
default

◆ ~Scheduler()

jobrocket::Scheduler::~Scheduler ( )

Calls shutdown before destruction.

Member Function Documentation

◆ auto_worker_count_value()

uint32_t jobrocket::Scheduler::auto_worker_count_value ( )

Gets the number of threads created when auto_worker_count is used on startup.

◆ core_count()

uint32_t jobrocket::Scheduler::core_count ( )
inline

Gets the number of real CPU cores on the current platform.

◆ hardware_thread_count()

uint32_t jobrocket::Scheduler::hardware_thread_count ( )
inline

Gets the number of threads available on the current platform including hyperthreads.

◆ num_main_threads()

uint32_t jobrocket::Scheduler::num_main_threads ( )
inline

Gets the max number of main threads the scheduler can support.

◆ num_workers()

uint32_t jobrocket::Scheduler::num_workers ( )
inline

Gets the number of workers active within the scheduler.

◆ register_main_thread()

void jobrocket::Scheduler::register_main_thread ( )

Registers the current thread as a main thread as long as the amount of main threads registered doesn't exceed num_main_threads. Can be called from any std::thread and is used to register threads that interact with the Scheduler and job system but aren't worker threads - A games render thread for example.

◆ schedule_job()

void jobrocket::Scheduler::schedule_job ( Job job)

Schedules a job onto the current threads local worker queue, making the job ready to execute

◆ shutdown()

void jobrocket::Scheduler::shutdown ( )

Shuts down the scheduler by waiting until all workers have completed the current job. All jobs sitting in worker queues are discarded

◆ startup()

void jobrocket::Scheduler::startup ( int32_t  num_threads,
int32_t  num_main_threads 
)

Starts the scheduler and all worker threads. Makes the startup thread wait until all workers are ready

◆ thread_local_worker()

Worker * jobrocket::Scheduler::thread_local_worker ( )

Gets a pointer to the current threads associated worker.

Member Data Documentation

◆ auto_thread_count

constexpr int32_t jobrocket::Scheduler::auto_thread_count = -1
static

Flag for letting the scheduler decide how many worker threads to create.

◆ job_capacity_per_worker

constexpr uint32_t jobrocket::Scheduler::job_capacity_per_worker = 4096
static