A lightweight thread pool scheduler for processing concurrent jobs in parallel.
More...
#include <JobSystem.hpp>
|
| void | initialize (unsigned int threadCount=0) |
| | Spawns worker threads.
|
| void | shutdown () |
| | Shuts down all worker threads and waits for them to join.
|
| void | pushJob (std::function< void()> job) |
| | Enqueues a single void-returning task.
|
| void | parallelFor (int count, std::function< void(int)> func) |
| | Splits a total loop count into chunks and evaluates them in parallel.
|
| unsigned int | getThreadCount () const |
| | Returns active thread count.
|
| bool | tryExecuteOneJob () |
A lightweight thread pool scheduler for processing concurrent jobs in parallel.
◆ JobSystem()
| Engine::JobSystem::JobSystem |
( |
| ) |
|
|
privatedefault |
◆ ~JobSystem()
| Engine::JobSystem::~JobSystem |
( |
| ) |
|
|
private |
◆ getInstance()
| JobSystem & Engine::JobSystem::getInstance |
( |
| ) |
|
|
inlinestatic |
Get the singleton instance.
◆ getThreadCount()
| unsigned int Engine::JobSystem::getThreadCount |
( |
| ) |
const |
|
inline |
Returns active thread count.
◆ initialize()
| void Engine::JobSystem::initialize |
( |
unsigned int | threadCount = 0 | ) |
|
Spawns worker threads.
- Parameters
-
| threadCount | Number of worker threads. Defaults to std::thread::hardware_concurrency() - 1. |
◆ parallelFor()
| void Engine::JobSystem::parallelFor |
( |
int | count, |
|
|
std::function< void(int)> | func ) |
Splits a total loop count into chunks and evaluates them in parallel.
◆ pushJob()
| void Engine::JobSystem::pushJob |
( |
std::function< void()> | job | ) |
|
Enqueues a single void-returning task.
◆ shutdown()
| void Engine::JobSystem::shutdown |
( |
| ) |
|
Shuts down all worker threads and waits for them to join.
◆ tryExecuteOneJob()
| bool Engine::JobSystem::tryExecuteOneJob |
( |
| ) |
|
◆ workerThreadLoop()
| void Engine::JobSystem::workerThreadLoop |
( |
| ) |
|
|
private |
◆ buffer
| std::unique_ptr<Cell[]> Engine::JobSystem::buffer |
|
private |
◆ bufferMask
| size_t Engine::JobSystem::bufferMask {0} |
|
private |
◆ dequeuePos
| std::atomic<size_t> Engine::JobSystem::dequeuePos {0} |
|
private |
◆ enqueuePos
| std::atomic<size_t> Engine::JobSystem::enqueuePos {0} |
|
private |
◆ initialized
| std::atomic<bool> Engine::JobSystem::initialized {false} |
|
private |
◆ jobSemaphore
| std::counting_semaphore<65536> Engine::JobSystem::jobSemaphore {0} |
|
private |
◆ stop
| std::atomic<bool> Engine::JobSystem::stop {false} |
|
private |
◆ workers
| std::vector<std::thread> Engine::JobSystem::workers |
|
private |
The documentation for this class was generated from the following files: