#include <JobPool.hpp>
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> | |
Job * | allocate_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... | |
|
default |
|
inline |
num_threads | Total number of threads including workers and main threads that will need to be able to allocate and free jobs |
capacity | The max number of jobs available to allocate per thread |
|
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
|
inline |
Iterates the free-list and frees all jobs previously added with free_job
|
inline |
Adds a job to a list to free later.
|
inline |
Resets all free lists and allocators.