Devel Lib
Devel::Threading::CThreadPool Class Reference

A class that implements a thread pool for executing tasks concurrently. More...

#include <ThreadPool.h>

Public Types

enum  EError { ESuccess , EAlreadyExecuted }
 An enumeration of possible errors that can occur when executing the thread pool. More...
 

Public Member Functions

 CThreadPool ()
 Default constructor for CThreadPool.
 
 CThreadPool (const size_t i_nWorkerCount)
 Constructor that sets the worker count for the thread pool. More...
 
 CThreadPool (CThreadPool &i_oPool)=delete
 Deleted copy constructor for CThreadPool. This copy constructor is explicitly deleted to prevent copying of CThreadPool objects. More...
 
 CThreadPool (CThreadPool *i_pPool)=delete
 Deleted constructor for CThreadPool that takes a pointer. This constructor is explicitly deleted to prevent creation of CThreadPool objects using a pointer to another CThreadPool object. More...
 
EError execute ()
 Executes the thread pool with the current worker count. More...
 
EError execute (const size_t i_nWorkerCount)
 Executes the thread pool with a specified worker count. More...
 
void stop (bool i_fClearTasks=true)
 Stops the execution of the thread pool. More...
 
void addTask (const ThreadPoolTaskFn &i_oTask)
 Adds a task to the task queue. More...
 
void addTask (ThreadPoolTaskFn &&i_oTask)
 Adds a task to the task queue. More...
 
void setWorkerCount (const size_t i_nWorkerCount)
 Sets the worker count for the thread pool. More...
 
size_t workerCount () const
 Returns the current worker count of the thread pool. More...
 
bool isExecuted () const
 Checks if the thread pool has been executed. More...
 

Detailed Description

A class that implements a thread pool for executing tasks concurrently.

The CThreadPool class manages a fixed number of worker threads that execute tasks from a task queue.

Member Enumeration Documentation

◆ EError

An enumeration of possible errors that can occur when executing the thread pool.

Enumerator
ESuccess 

The operation was successful.

EAlreadyExecuted 

The thread pool has already been executed.

Constructor & Destructor Documentation

◆ CThreadPool() [1/3]

Devel::Threading::CThreadPool::CThreadPool ( const size_t  i_nWorkerCount)
inlineexplicit

Constructor that sets the worker count for the thread pool.

Parameters
i_nWorkerCountThe number of worker threads in the thread pool.

◆ CThreadPool() [2/3]

Devel::Threading::CThreadPool::CThreadPool ( CThreadPool i_oPool)
delete

Deleted copy constructor for CThreadPool. This copy constructor is explicitly deleted to prevent copying of CThreadPool objects.

Parameters
i_oPoolThe CThreadPool object to be copied.

◆ CThreadPool() [3/3]

Devel::Threading::CThreadPool::CThreadPool ( CThreadPool i_pPool)
delete

Deleted constructor for CThreadPool that takes a pointer. This constructor is explicitly deleted to prevent creation of CThreadPool objects using a pointer to another CThreadPool object.

Parameters
i_pPoolA pointer to a CThreadPool object.

Member Function Documentation

◆ addTask() [1/2]

void Devel::Threading::CThreadPool::addTask ( const ThreadPoolTaskFn &  i_oTask)
inline

Adds a task to the task queue.

Parameters
i_oTaskThe task to be added.

◆ addTask() [2/2]

void Devel::Threading::CThreadPool::addTask ( ThreadPoolTaskFn &&  i_oTask)
inline

Adds a task to the task queue.

Parameters
i_oTaskThe task to be added.

◆ execute() [1/2]

Devel::Threading::CThreadPool::EError Devel::Threading::CThreadPool::execute ( )

Executes the thread pool with the current worker count.

Returns
The execution result.

◆ execute() [2/2]

EError Devel::Threading::CThreadPool::execute ( const size_t  i_nWorkerCount)
inline

Executes the thread pool with a specified worker count.

Parameters
i_nWorkerCountThe number of worker threads to use in the thread pool.
Returns
The execution result.

◆ isExecuted()

bool Devel::Threading::CThreadPool::isExecuted ( ) const
inline

Checks if the thread pool has been executed.

Returns
True if the thread pool has been executed, false otherwise.

◆ setWorkerCount()

void Devel::Threading::CThreadPool::setWorkerCount ( const size_t  i_nWorkerCount)
inline

Sets the worker count for the thread pool.

Parameters
i_nWorkerCountThe number of worker threads to use in the thread pool.

◆ stop()

void Devel::Threading::CThreadPool::stop ( bool  i_fClearTasks = true)

Stops the execution of the thread pool.

Parameters
i_fClearTasksFlag indicating whether to clear the task queue.

◆ workerCount()

size_t Devel::Threading::CThreadPool::workerCount ( ) const
inline

Returns the current worker count of the thread pool.

Returns
The worker count.

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