HPC_Voxel_Engine 0.2.0
High-Performance C++ Voxel Engine
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
Core::ThreadPool Class Reference

Manages a pool of worker threads that consume tasks from a ThreadSafeQueue. Utilizes C++20 std::jthread for automatic joining. More...

#include <src/core/ThreadPool.h>

Collaboration diagram for Core::ThreadPool:
Collaboration graph

Public Member Functions

 ThreadPool ()
 Constructs the thread pool. Defaults to (Hardware Threads - 1) to leave the main thread free.
 
 ~ThreadPool ()
 Destructor. Stops all threads and joins them.
 
void submit (std::function< void()> objJob)
 Submits a void() function/lambda to the pool.
 

Private Member Functions

void worker_loop (std::stop_token st)
 The main loop for worker threads.
 

Private Attributes

std::vector< std::jthread > m_objJThreads
 
std::atomic< bool > m_bDone
 
ThreadSafeQueue< std::function< void()> > m_ObjQueue
 

Detailed Description

Manages a pool of worker threads that consume tasks from a ThreadSafeQueue. Utilizes C++20 std::jthread for automatic joining.

Constructor & Destructor Documentation

◆ ThreadPool()

Core::ThreadPool::ThreadPool ( )
inline

Constructs the thread pool. Defaults to (Hardware Threads - 1) to leave the main thread free.

Here is the call graph for this function:

◆ ~ThreadPool()

Core::ThreadPool::~ThreadPool ( )
inline

Destructor. Stops all threads and joins them.

Here is the call graph for this function:

Member Function Documentation

◆ submit()

void Core::ThreadPool::submit ( std::function< void()>  objJob)
inline

Submits a void() function/lambda to the pool.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ worker_loop()

void Core::ThreadPool::worker_loop ( std::stop_token  st)
inlineprivate

The main loop for worker threads.

Parameters
stC++20 Stop Token to check for shutdown requests.
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ m_bDone

std::atomic<bool> Core::ThreadPool::m_bDone
private

◆ m_objJThreads

std::vector<std::jthread> Core::ThreadPool::m_objJThreads
private

◆ m_ObjQueue

ThreadSafeQueue<std::function<void()> > Core::ThreadPool::m_ObjQueue
private

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