PicoScenes API Docs
 
Loading...
Searching...
No Matches
TaggedThreadPool< ThreadCountCompileTime > Class Template Reference

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 &&params, 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.
 

Detailed Description

template<unsigned ThreadCountCompileTime = 1>
class TaggedThreadPool< ThreadCountCompileTime >

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.

Template Parameters
ThreadCountCompileTimeThe number of threads to create at compile time.

Definition at line 37 of file TaggedThreadPool.hxx.

Constructor & Destructor Documentation

◆ TaggedThreadPool()

template<unsigned ThreadCountCompileTime = 1>
TaggedThreadPool< ThreadCountCompileTime >::TaggedThreadPool ( const int  threadCount = ThreadCountCompileTime,
const std::string &  threadNamePrefix = std::string{} 
)
inlineexplicit

Constructs a TaggedThreadPool with a specified number of threads.

Parameters
threadCountThe number of threads to create.
threadNamePrefixA prefix for naming threads.

Definition at line 45 of file TaggedThreadPool.hxx.

◆ ~TaggedThreadPool()

template<unsigned ThreadCountCompileTime = 1>
TaggedThreadPool< ThreadCountCompileTime >::~TaggedThreadPool ( )
inline

Destroys the thread pool and shuts down all threads.

Definition at line 132 of file TaggedThreadPool.hxx.

Member Function Documentation

◆ AddJob()

template<unsigned ThreadCountCompileTime = 1>
void TaggedThreadPool< ThreadCountCompileTime >::AddJob ( const std::function< void()> &  task)
inline

Adds a simple job to the thread pool.

Parameters
taskThe task function to execute.

Definition at line 100 of file TaggedThreadPool.hxx.

References TaggedThreadPool< ThreadCountCompileTime >::addJob().

◆ addJob()

template<unsigned ThreadCountCompileTime = 1>
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 TaggedThreadPool< ThreadCountCompileTime >::addJob ( Task &&  task,
Params &&  params,
const std::optional< uint32_t > &  threadSN = std::nullopt 
)
inline

Adds a job to the thread pool. And threadSN is an integer starting from 0.

Template Parameters
TaskThe type of the task function.
ParamsThe type of the parameters for the task.
Parameters
taskThe task function to execute.
paramsThe parameters for the task.
threadSNOptional thread sequence number to specify a thread.

Definition at line 84 of file TaggedThreadPool.hxx.

Referenced by TaggedThreadPool< ThreadCountCompileTime >::AddJob().

◆ addThread()

template<unsigned ThreadCountCompileTime = 1>
void TaggedThreadPool< ThreadCountCompileTime >::addThread ( const int  numThreads2Add)
inline

Adds a specified number of threads to the pool.

Parameters
numThreads2AddThe number of threads to add.

Definition at line 54 of file TaggedThreadPool.hxx.

◆ taskCount()

template<unsigned ThreadCountCompileTime = 1>
size_t TaggedThreadPool< ThreadCountCompileTime >::taskCount ( ) const
inline

Gets the total number of tasks in the pool.

Returns
The number of tasks.

Definition at line 120 of file TaggedThreadPool.hxx.

References TaggedThreadPool< ThreadCountCompileTime >::taskCount().

Referenced by TaggedThreadPool< ThreadCountCompileTime >::taskCount().

◆ threadCount()

template<unsigned ThreadCountCompileTime = 1>
size_t TaggedThreadPool< ThreadCountCompileTime >::threadCount ( ) const
inline

Gets the number of threads in the pool.

Returns
The number of threads.

Definition at line 111 of file TaggedThreadPool.hxx.


The documentation for this class was generated from the following file: