A pool with pre-created threads, allowing to queue work asynchronously. More...
Public Member Functions | |
ThreadPool (unsigned int threadCount=0) noexcept | |
~ThreadPool () | |
unsigned int | getThreadCount () const |
Thread * | getThread (unsigned int index) const |
void | addTask (nkMemory::UniquePtr< Task > task) |
void | cancelPendingTasks () |
void | flush () |
void | resizeForThreadCount (unsigned int threadCount) |
A pool with pre-created threads, allowing to queue work asynchronously.
|
noexcept |
Constructor.
threadCount | The number of threads the pool should prepare. |
nkTasks::ThreadPool::~ThreadPool | ( | ) |
Destructor.
unsigned int nkTasks::ThreadPool::getThreadCount | ( | ) | const |
Thread* nkTasks::ThreadPool::getThread | ( | unsigned int | index | ) | const |
index | The index of the thread to retrieve, within the pool. |
void nkTasks::ThreadPool::addTask | ( | nkMemory::UniquePtr< Task > | task | ) |
Add a task to be pooled.
task | The task to be processed. |
void nkTasks::ThreadPool::cancelPendingTasks | ( | ) |
Cancels all the tasks queued, waiting to be picked by a thread from the pool.
void nkTasks::ThreadPool::flush | ( | ) |
Flushes all pending work and only returns once the pool has processed everything.
void nkTasks::ThreadPool::resizeForThreadCount | ( | unsigned int | threadCount | ) |
Resizes the pool with a different amount of threads.
threadCount | The number of threads the pool should feature. |