5 #include "Threading/SafeQueue/SafeQueue.h"
10 typedef std::function<void()> ThreadPoolTaskFn;
28 : m_nWorkerCount(3), m_fIsExecuted(false) {
69 void stop(
bool i_fClearTasks =
true);
78 inline void addTask(
const ThreadPoolTaskFn &i_oTask) { this->m_aoTasks.
enqueue(i_oTask); }
82 inline void addTask(ThreadPoolTaskFn &&i_oTask) { this->m_aoTasks.
enqueue(std::move(i_oTask)); }
87 this->m_nWorkerCount = (i_nWorkerCount == 0 ? 1 : i_nWorkerCount);
102 size_t m_nWorkerCount;
106 std::vector<std::thread> m_aoWorker;
void enqueue(const T &i_tValue)
Enqueues an element into the safe queue.
Definition: SafeQueue.h:127
A class that implements a thread pool for executing tasks concurrently.
Definition: ThreadPool.h:16
CThreadPool(CThreadPool &i_oPool)=delete
Deleted copy constructor for CThreadPool. This copy constructor is explicitly deleted to prevent copy...
EError execute(const size_t i_nWorkerCount)
Executes the thread pool with a specified worker count.
Definition: ThreadPool.h:62
EError
An enumeration of possible errors that can occur when executing the thread pool.
Definition: ThreadPool.h:20
@ EAlreadyExecuted
The thread pool has already been executed.
Definition: ThreadPool.h:22
@ ESuccess
The operation was successful.
Definition: ThreadPool.h:21
CThreadPool()
Default constructor for CThreadPool.
Definition: ThreadPool.h:27
void stop(bool i_fClearTasks=true)
Stops the execution of the thread pool.
Definition: ThreadPool.cpp:20
size_t workerCount() const
Returns the current worker count of the thread pool.
Definition: ThreadPool.h:93
CThreadPool(const size_t i_nWorkerCount)
Constructor that sets the worker count for the thread pool.
Definition: ThreadPool.h:33
EError execute()
Executes the thread pool with the current worker count.
Definition: ThreadPool.cpp:5
bool isExecuted() const
Checks if the thread pool has been executed.
Definition: ThreadPool.h:97
void addTask(const ThreadPoolTaskFn &i_oTask)
Adds a task to the task queue.
Definition: ThreadPool.h:78
void setWorkerCount(const size_t i_nWorkerCount)
Sets the worker count for the thread pool.
Definition: ThreadPool.h:86
void addTask(ThreadPoolTaskFn &&i_oTask)
Adds a task to the task queue.
Definition: ThreadPool.h:82
CThreadPool(CThreadPool *i_pPool)=delete
Deleted constructor for CThreadPool that takes a pointer. This constructor is explicitly deleted to p...
The namespace encapsulating threading related classes and functions in the Devel framework.