|
R-Type
Distributed multiplayer game engine in C++
|
Concrete implementation of IThreadPool. More...
#include <ThreadPool.hpp>


Public Member Functions | |
| ThreadPool (size_t threadCount) | |
| ~ThreadPool () override | |
| void | enqueue (Task task) override |
| Enqueue a task to be executed by the thread pool. | |
| void | start () override |
| Start all threads in the pool. | |
| void | stop () override |
| Stop all threads and clean up resources. | |
| size_t | size () const override |
| Get the number of threads in the pool. | |
Public Member Functions inherited from server::IThreadPool | |
| virtual | ~IThreadPool ()=default |
Private Member Functions | |
| void | _workerLoop (std::stop_token stopToken) |
| Worker thread main loop Continuously pulls tasks from the queue and executes them. | |
Private Attributes | |
| size_t | _threadCount |
| std::vector< std::jthread > | _workers |
| ThreadSafeQueue< Task > | _taskQueue |
Additional Inherited Members | |
Public Types inherited from server::IThreadPool | |
| using | Task = std::function< void()> |
Concrete implementation of IThreadPool.
Manages a fixed number of worker threads executing tasks concurrently. Uses a thread-safe queue to distribute tasks among workers.
Definition at line 23 of file ThreadPool.hpp.
|
explicit |
Definition at line 13 of file ThreadPool.cpp.
|
override |
Definition at line 15 of file ThreadPool.cpp.
References LOG_ERROR, and stop().

|
private |
Worker thread main loop Continuously pulls tasks from the queue and executes them.
| stopToken | Token to check for stop requests |
Definition at line 86 of file ThreadPool.cpp.
References _taskQueue, LOG_ERROR, and ThreadSafeQueue< T >::pop().
Referenced by start().

|
overridevirtual |
Enqueue a task to be executed by the thread pool.
| task | Task function |
Implements server::IThreadPool.
Definition at line 68 of file ThreadPool.cpp.
References _taskQueue, _workers, LOG_WARNING, and ThreadSafeQueue< T >::push().

|
overridevirtual |
Get the number of threads in the pool.
Implements server::IThreadPool.
Definition at line 82 of file ThreadPool.cpp.
References _threadCount.
|
overridevirtual |
Start all threads in the pool.
Implements server::IThreadPool.
Definition at line 24 of file ThreadPool.cpp.
References _threadCount, _workerLoop(), _workers, LOG_DEBUG, LOG_INFO, and LOG_WARNING.

|
overridevirtual |
Stop all threads and clean up resources.
Implements server::IThreadPool.
Definition at line 45 of file ThreadPool.cpp.
References _taskQueue, _threadCount, _workers, LOG_INFO, and ThreadSafeQueue< T >::push().
Referenced by ~ThreadPool().

|
private |
Definition at line 44 of file ThreadPool.hpp.
Referenced by _workerLoop(), enqueue(), and stop().
|
private |
Definition at line 42 of file ThreadPool.hpp.
|
private |
Definition at line 43 of file ThreadPool.hpp.