A thread pool with tagged threads for task management. More...
#include <TaggedThreadPool.hxx>
Public Member Functions | |
TaggedThreadPool (const int threadCount=ThreadCountCompileTime, const std::string &threadNamePrefix=std::string{}) | |
Constructs a TaggedThreadPool with a specified number of threads. | |
void | addThread (const int numThreads2Add) |
Adds a specified number of threads to the pool. | |
template<typename Task , typename Params , typename = std::enable_if_t<std::is_invocable_v<Task, const std::any &> && std::is_same_v<std::decay_t<Params>, std::any>>> | |
void | addJob (Task &&task, Params &¶ms, const std::optional< uint32_t > &threadSN=std::nullopt) |
Adds a job to the thread pool. And threadSN is an integer starting from 0. | |
void | AddJob (const std::function< void()> &task) |
Adds a simple job to the thread pool. | |
size_t | threadCount () const |
Gets the number of threads in the pool. | |
size_t | taskCount () const |
Gets the total number of tasks in the pool. | |
~TaggedThreadPool () | |
Destroys the thread pool and shuts down all threads. | |
A thread pool with tagged threads for task management.
This class manages a pool of threads, allowing tasks to be added and executed either in a shared queue or in a thread-specific queue.
ThreadCountCompileTime | The number of threads to create at compile time. |
Definition at line 37 of file TaggedThreadPool.hxx.
|
inlineexplicit |
Constructs a TaggedThreadPool with a specified number of threads.
threadCount | The number of threads to create. |
threadNamePrefix | A prefix for naming threads. |
Definition at line 45 of file TaggedThreadPool.hxx.
|
inline |
Destroys the thread pool and shuts down all threads.
Definition at line 132 of file TaggedThreadPool.hxx.
|
inline |
Adds a simple job to the thread pool.
task | The task function to execute. |
Definition at line 100 of file TaggedThreadPool.hxx.
References TaggedThreadPool< ThreadCountCompileTime >::addJob().
|
inline |
Adds a job to the thread pool. And threadSN is an integer starting from 0.
Task | The type of the task function. |
Params | The type of the parameters for the task. |
task | The task function to execute. |
params | The parameters for the task. |
threadSN | Optional thread sequence number to specify a thread. |
Definition at line 84 of file TaggedThreadPool.hxx.
Referenced by TaggedThreadPool< ThreadCountCompileTime >::AddJob().
|
inline |
Adds a specified number of threads to the pool.
numThreads2Add | The number of threads to add. |
Definition at line 54 of file TaggedThreadPool.hxx.
|
inline |
Gets the total number of tasks in the pool.
Definition at line 120 of file TaggedThreadPool.hxx.
References TaggedThreadPool< ThreadCountCompileTime >::taskCount().
Referenced by TaggedThreadPool< ThreadCountCompileTime >::taskCount().
|
inline |
Gets the number of threads in the pool.
Definition at line 111 of file TaggedThreadPool.hxx.