|
co_ecs 0.9.0
Cobalt ECS
|
Generic thread pool implementation. More...
#include <thread_pool.hpp>
Classes | |
| class | worker |
| Thread pool worker. More... | |
Public Types | |
| using | thread_t = std::thread |
Public Member Functions | |
| thread_pool (std::size_t num_workers=std::thread::hardware_concurrency()) | |
| Construct thread pool with num_workers workers. | |
| ~thread_pool () | |
| Destroy thread pool, worker threads are notified to exit and joined. | |
| thread_pool (const thread_pool &)=delete | |
| thread_pool & | operator= (const thread_pool &)=delete |
| thread_pool (thread_pool &&)=delete | |
| thread_pool & | operator= (thread_pool &&)=delete |
| task_t * | submit (auto &&func, task_t *parent=nullptr) |
| Submit a task to a thread pool. | |
| void | wait (task_t *task) |
| Wait a task to complete. | |
| worker & | get_worker_by_id (std::size_t id) noexcept |
| Get worker by ID. | |
| std::size_t | num_workers () const noexcept |
| Return the number of workers. | |
Static Public Member Functions | |
| static thread_pool & | get () |
| Get thread pool instance. | |
| static worker & | current_worker () noexcept |
| Get current worker. | |
Generic thread pool implementation.
Creates N worker threads. Each thread has its own local task queue that it can push/pop task items to/from. Once there's no tasks in local queue a worker thread tries to steal a task from a random worker.
| using co_ecs::thread_pool::thread_t = std::thread |
|
inline |
Construct thread pool with num_workers workers.
| num_workers | The number of workers to create |
|
inline |
Destroy thread pool, worker threads are notified to exit and joined.
|
delete |
|
delete |
|
inlinestaticnoexcept |
Get current worker.
|
inlinestatic |
Get thread pool instance.
|
inlinenoexcept |
Get worker by ID.
| id | Worker ID |
|
inlinenoexcept |
Return the number of workers.
|
delete |
|
delete |
Submit a task to a thread pool.
| func | Function |
| parent | Parent task pointer |
|
inline |
Wait a task to complete.
| task |