A global thread pool.
More...
#include <threadpool.h>
A global thread pool.
Definition at line 43 of file threadpool.h.
◆ ~threadpool()
| tools::threadpool::~threadpool |
( |
| ) |
|
Definition at line 49 of file threadpool.cpp.
49 {
50 try
51 {
52 const boost::unique_lock<boost::mutex> lock(mutex);
53 running = false;
54 has_work.notify_all();
55 }
56 catch (...)
57 {
58
59
60 running = false;
61 has_work.notify_all();
62 }
63 for (size_t i = 0; i<threads.size(); i++) {
64 try { threads[i].join(); }
65 catch (...) { }
66 }
67}
◆ get_max_concurrency()
| unsigned int tools::threadpool::get_max_concurrency |
( |
| ) |
const |
◆ getInstance()
| threadpool & tools::threadpool::getInstance |
( |
| ) |
|
|
inlinestatic |
Definition at line 46 of file threadpool.h.
46 {
47 static threadpool instance;
48 return instance;
49 }
◆ getNewForUnitTests()
| threadpool * tools::threadpool::getNewForUnitTests |
( |
unsigned | max_threads = 0 | ) |
|
|
inlinestatic |
Definition at line 50 of file threadpool.h.
50 {
51 return new threadpool(max_threads);
52 }
◆ submit()
| void tools::threadpool::submit |
( |
waiter * | waiter, |
|
|
std::function< void()> | f, |
|
|
bool | leaf = false ) |
Definition at line 69 of file threadpool.cpp.
69 {
71 boost::unique_lock<boost::mutex> lock(mutex);
72 if (!leaf && ((active == max && !queue.empty()) || depth > 0)) {
73
74
75 lock.unlock();
76 ++depth;
77 is_leaf = leaf;
78 f();
79 --depth;
80 is_leaf = false;
81 } else {
82 if (obj)
83 obj->inc();
84 if (leaf)
85 queue.push_front({obj, f, leaf});
86 else
87 queue.push_back({obj, f, leaf});
88 has_work.notify_one();
89 }
90}
#define CHECK_AND_ASSERT_THROW_MES(expr, message)
The documentation for this class was generated from the following files:
- /home/abuild/rpmbuild/BUILD/electroneum-5.1.3.1-build/electroneum-5.1.3.1/src/common/threadpool.h
- /home/abuild/rpmbuild/BUILD/electroneum-5.1.3.1-build/electroneum-5.1.3.1/src/common/threadpool.cpp