|
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> | |
| void | PushImpl (Args &&... args) |
| Push a job implementing ThreadPoolJob to the thread pool. | |
| template<typename Lambda , typename... Args> | |
| auto | Push (Lambda &&func, Args &&... 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 () | |
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 |
| JobQueue::Writer | mJobsWriter |
| Vector< Thread > | mThreads |
Atomic, lock-free Thread Pool implementation with fixed bounds.
| Foundation::Async::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. |
| alloc | Allocator to use for internal and job allocations |
| name | Prefix for worker thread names ("name@id") |
| Foundation::Async::ThreadPool::~ThreadPool | ( | ) |
Shutdown, without waiting for pending jobs.
| void Foundation::Async::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::Async::ThreadPool::Shutdown | ( | ) |
Shutdown the ThreadPool, potentially cancelling all pending jobs.
|
private |
|
private |
|
private |
|
private |