|
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") | |
| template<typename T , typename... Args> requires std::is_base_of_v<Job, T> | |
| void | PushImpl (JobPriority priority, Args &&... args) |
| template<typename T , typename... Args> requires std::is_base_of_v<Job, T> | |
| void | PushImpl (Args &&... args) |
| template<typename T , typename... Args> requires std::is_base_of_v<Job, T> | |
| void | PushImplAlloc (Allocator *jobAllocator, Args &&... args) |
| Push a job with an explicit allocator for the job object. | |
| template<typename T , typename... Args> requires std::is_base_of_v<Job, T> | |
| void | PushImplAlloc (JobPriority priority, Allocator *jobAllocator, Args &&... args) |
| template<typename Lambda , typename... Args> | |
| auto | Push (JobPriority priority, Lambda &&func, Args const &... args) |
| Push a lambda job to the thread pool. | |
| template<typename Lambda , typename... Args> | |
| auto | Push (Lambda &&func, Args const &... args) |
| template<typename Lambda , typename... Args> | |
| auto | PushAlloc (Allocator *jobAllocator, Lambda &&func, Args const &... args) |
| Push a lambda job with an explicit allocator for the job object. | |
| template<typename Lambda , typename... Args> | |
| auto | PushAlloc (JobPriority priority, Allocator *jobAllocator, Lambda &&func, Args const &... args) |
| size_t | GetWorkerCount () const noexcept |
| Number of worker threads. Worker ids passed to Execute are in [0, this). | |
| size_t | GetParallelForConcurrency () const noexcept |
| Number of distinct worker ids a ParallelFor functor may see (workers + the participating caller). Size per-worker scratch to this. | |
| void | Shutdown () |
| Stop accepting work, drain accepted jobs, and stop all workers. | |
| void | Join () |
| Wait for all scheduled jobs to complete. | |
| ~ThreadPool () | |
| Join accepted jobs and stop all workers. | |
| size_t | GetPendingJobCount () const noexcept |
| size_t | GetCompletedJobCount () const noexcept |
| size_t | GetTotalJobCount () const noexcept |
Static Public Member Functions | |
| static const size_t | CalcTaskSize (size_t size) |
Private Member Functions | |
| void | ThreadPoolWorker (size_t id) |
| bool | BeginSubmit () noexcept |
| void | EndSubmit () noexcept |
| template<typename T , typename... Args> requires std::is_base_of_v<Job, T> | |
| void | PushImplInternal (JobPriority priority, Allocator *jobAllocator, Args &&... args) |
| template<typename Lambda , typename... Args> | |
| auto | PushLambdaInternal (JobPriority priority, Allocator *jobAllocator, Lambda &&func, Args const &... args) |
Static Private Member Functions | |
| static constexpr size_t | PriorityIndex (JobPriority priority) noexcept |
Private Attributes | |
| Allocator * | mAllocator |
| String | mName |
| Atomic< bool > | mAccepting {true} |
| Mutex | mSubmitMutex |
| CondVar | mSubmitCV |
| size_t | mSubmitting {} |
| Atomic< bool > | mShutdown {false} |
| Atomic< size_t > | mWakeEpoch {0} |
| Atomic< size_t > | mProgressEpoch {0} |
| Atomic< size_t > | mComplete {0} |
| Atomic< size_t > | mTotal {0} |
| JobQueues | 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" |
||
| ) |
| Foundation::Core::ThreadPool::~ThreadPool | ( | ) |
Join accepted jobs and stop all workers.
|
inlineprivatenoexcept |
|
inlinestatic |
Aligns a number to upper, closest power of 2 so that it's a valid maxTasks size.
|
inlineprivatenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
Number of distinct worker ids a ParallelFor functor may see (workers + the participating caller). Size per-worker scratch to this.
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
Number of worker threads. Worker ids passed to Execute are in [0, this).
| void Foundation::Core::ThreadPool::Join | ( | ) |
Wait for all scheduled jobs to complete.
|
inlinestaticconstexprprivatenoexcept |
|
inline |
Push a lambda job to the thread pool.
|
inline |
|
inline |
Push a lambda job with an explicit allocator for the job object.
| jobAllocator | Optional allocator for the job object. If null, the thread pool allocator is used. |
|
inline |
|
inline |
|
inline |
|
inline |
Push a job with an explicit allocator for the job object.
| jobAllocator | Optional allocator for the job object. If null, the thread pool allocator is used. |
|
inline |
|
inlineprivate |
|
inlineprivate |
| void Foundation::Core::ThreadPool::Shutdown | ( | ) |
Stop accepting work, drain accepted jobs, and stop all workers.
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |