Jobrocket
jobrocket::JobPool Class Reference

#include <JobPool.hpp>

Overview

JobPools allocate and recycle Job objects efficiently and in a thread-safe manner. Preferably only one JobPool and one Scheduler should be active at any given time in an application as the pool must maintain as many allocators and free-lists as there are worker and main threads which can take up a bit of memory for larger numbers of threads.

Public Member Functions

 JobPool ()=default
 
 JobPool (const uint32_t num_threads, const uint32_t capacity)
 
template<typename Fn , typename... Args>
Joballocate_job (Fn function, Args &&... args)
 
void free_all_this_thread ()
 Iterates the free-list and frees all jobs previously added with free_job More...
 
void free_job (Job *&job)
 Adds a job to a list to free later. More...
 
void reset ()
 Resets all free lists and allocators. More...
 

Constructor & Destructor Documentation

◆ JobPool() [1/2]

jobrocket::JobPool::JobPool ( )
default

◆ JobPool() [2/2]

jobrocket::JobPool::JobPool ( const uint32_t  num_threads,
const uint32_t  capacity 
)
inline
Parameters
num_threadsTotal number of threads including workers and main threads that will need to be able to allocate and free jobs
capacityThe max number of jobs available to allocate per thread

Member Function Documentation

◆ allocate_job()

template<typename Fn , typename... Args>
Job* jobrocket::JobPool::allocate_job ( Fn  function,
Args &&...  args 
)
inline

Allocates a new job. Checks first if the current threads free-list is full and if so, frees all previously freed jobs for this thread before allocating

◆ free_all_this_thread()

void jobrocket::JobPool::free_all_this_thread ( )
inline

Iterates the free-list and frees all jobs previously added with free_job

◆ free_job()

void jobrocket::JobPool::free_job ( Job *&  job)
inline

Adds a job to a list to free later.

◆ reset()

void jobrocket::JobPool::reset ( )
inline

Resets all free lists and allocators.