|
Foundation
|
Atomic, lock-free Thread Pool implementation with fixed bounds. More...
#include <ThreadPool.hpp>
Public Member Functions | |
| ThreadPool (size_t numThreads, size_t maxTasks, Allocator *alloc, StringView name="ThreadPool") | |
| Construct a thread pool with the given number of worker threads. | |
| template<typename T , typename... Args> requires std::is_base_of_v<ThreadPoolJob, T> | |
| T * | PushImpl (Args &&... args) |
| Push a job implementing ThreadPoolJob to the thread pool. | |
| template<typename Lambda , typename... Args> | |
| auto | Push (Lambda &&func, Args const &... args) |
| Push a lambda job to the thread pool. | |
| void | Shutdown () |
| Shutdown the ThreadPool, potentially cancelling all pending jobs. | |
| void | Join () |
| Wait for all scheduled jobs to complete. | |
| ~ThreadPool () | |
| Shutdown, without waiting for pending jobs. | |
| size_t | GetPendingJobCount () const noexcept |
| size_t | GetCompletedJobCount () const noexcept |
| size_t | GetTotalJobCount () const noexcept |
Static Public Member Functions | |
| static constexpr size_t | getTaskSize (size_t size) |
Private Member Functions | |
| void | ThreadPoolWorker (size_t id) |
Private Attributes | |
| Allocator * | mAllocator |
| String | mName |
| Atomic< bool > | mShutdown {false} |
| Atomic< size_t > | mComplete {0} |
| Atomic< size_t > | mTotal {0} |
| JobQueue | mJobs |
| Vector< Thread > | mThreads |
Atomic, lock-free Thread Pool implementation with fixed bounds.
| Foundation::Core::ThreadPool::ThreadPool | ( | size_t | numThreads, |
| size_t | maxTasks, | ||
| Allocator * | alloc, | ||
| StringView | name = "ThreadPool" |
||
| ) |
Construct a thread pool with the given number of worker threads.
| numThreads | Number of worker threads to spawn. |
| maxTasks | Max number of tasks that can be queued. Must be a power of two - see getTaskSize |
| alloc | Allocator to use for internal and job allocations |
| name | Prefix for worker thread names ("name@id") |
| Foundation::Core::ThreadPool::~ThreadPool | ( | ) |
Shutdown, without waiting for pending jobs.
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinestaticconstexpr |
Aligns a number to upper, closest power of 2 so that it's a valid maxTasks size.
|
inlinenoexcept |
| void Foundation::Core::ThreadPool::Join | ( | ) |
Wait for all scheduled jobs to complete.
Push a lambda job to the thread pool.
Push a job implementing ThreadPoolJob to the thread pool.
| void Foundation::Core::ThreadPool::Shutdown | ( | ) |
Shutdown the ThreadPool, potentially cancelling all pending jobs.
|
private |
|
private |
|
private |