Simple thread pool executor for parallelizing diagram generation.
More...
Simple thread pool executor for parallelizing diagram generation.
Definition at line 30 of file thread_pool_executor.h.
#include <thread_pool_executor.h>
|
void | worker () |
| Main worker pool thread method - take task from queue and execute.
|
|
std::packaged_task< void()> | get () |
|
◆ thread_pool_executor() [1/3]
clanguml::util::thread_pool_executor::thread_pool_executor |
( |
unsigned int |
pool_size | ) |
|
|
explicit |
Constructor.
- Parameters
-
pool_size | Number of threads in the pool |
Definition at line 23 of file thread_pool_executor.cc.
25{
26 if (pool_size == 0U)
27 pool_size = std::thread::hardware_concurrency();
28
29 for (auto i = 0U; i < pool_size; i++) {
31 }
32}
◆ thread_pool_executor() [2/3]
◆ thread_pool_executor() [3/3]
◆ ~thread_pool_executor()
clanguml::util::thread_pool_executor::~thread_pool_executor |
( |
| ) |
|
◆ add()
std::future< void > clanguml::util::thread_pool_executor::add |
( |
std::function< void()> && |
task | ) |
|
Add a task to run on the pool.
- Parameters
-
- Returns
- Future, allowing awaiting the result
Definition at line 36 of file thread_pool_executor.cc.
37{
39
40 std::packaged_task<void()> ptask{std::move(task)};
41 auto res = ptask.get_future();
42
43 tasks_.emplace_back(std::move(ptask));
44
45 l.unlock();
47
48 return res;
49}
◆ get()
std::packaged_task< void()> clanguml::util::thread_pool_executor::get |
( |
| ) |
|
|
private |
Definition at line 73 of file thread_pool_executor.cc.
74{
76
79 throw std::runtime_error("Thread pool closing...");
80
82 }
83
84 auto res = std::move(
tasks_.front());
86 return res;
87}
◆ operator=() [1/2]
◆ operator=() [2/2]
◆ stop()
void clanguml::util::thread_pool_executor::stop |
( |
| ) |
|
Join all active threads in the pool.
Definition at line 51 of file thread_pool_executor.cc.
52{
55 if (thread.joinable())
56 thread.join();
57 }
58}
◆ worker()
void clanguml::util::thread_pool_executor::worker |
( |
| ) |
|
|
private |
Main worker pool thread method - take task from queue and execute.
Definition at line 60 of file thread_pool_executor.cc.
61{
62 try {
65
66 task();
67 }
68 }
69 catch (std::runtime_error &e) {
70 }
71}
◆ done_
std::atomic_bool clanguml::util::thread_pool_executor::done_ |
|
private |
◆ tasks_
std::deque<std::packaged_task<void()> > clanguml::util::thread_pool_executor::tasks_ |
|
private |
◆ tasks_cond_
std::condition_variable clanguml::util::thread_pool_executor::tasks_cond_ |
|
private |
◆ tasks_mutex_
std::mutex clanguml::util::thread_pool_executor::tasks_mutex_ |
|
private |
◆ threads_
std::vector<std::thread> clanguml::util::thread_pool_executor::threads_ |
|
private |
The documentation for this class was generated from the following files: