#include <thread_pool.h>
Definition at line 24 of file thread_pool.h.
◆ Thread_Pool() [1/3]
Botan::Thread_Pool::Thread_Pool |
( |
size_t |
pool_size = 0 | ) |
|
Initialize a thread pool with some number of threads
- Parameters
-
pool_size | number of threads in the pool, if 0 then some default value is chosen |
Definition at line 21 of file thread_pool.cpp.
22 {
23 if(pool_size == 0)
24 {
26
27
28
29
30
31 if(pool_size > 16)
32 pool_size = 16;
33 }
34
35 if(pool_size <= 1)
36 pool_size = 2;
37
38 m_shutdown = false;
39
40 for(size_t i = 0; i != pool_size; ++i)
41 {
42 m_workers.push_back(std::thread(&Thread_Pool::worker_thread, this));
43 }
44 }
size_t BOTAN_TEST_API get_cpu_available()
References Botan::OS::get_cpu_available().
◆ ~Thread_Pool()
Botan::Thread_Pool::~Thread_Pool |
( |
| ) |
|
|
inline |
◆ Thread_Pool() [2/3]
Botan::Thread_Pool::Thread_Pool |
( |
const Thread_Pool & |
| ) |
|
|
delete |
◆ Thread_Pool() [3/3]
◆ global_instance()
◆ operator=() [1/2]
◆ operator=() [2/2]
◆ queue_thunk()
void Botan::Thread_Pool::queue_thunk |
( |
std::function< void()> |
fn | ) |
|
Definition at line 66 of file thread_pool.cpp.
67 {
68 std::unique_lock<std::mutex> lock(m_mutex);
69
70 if(m_shutdown)
71 throw Invalid_State("Cannot add work after thread pool has shut down");
72
73 m_tasks.push_back(fn);
74 m_more_tasks.notify_one();
75 }
◆ run()
template<class F , class... Args>
auto Botan::Thread_Pool::run |
( |
F && |
f, |
|
|
Args &&... |
args |
|
) |
| -> std::future<typename std::result_of<F(Args...)>::type>
|
|
inline |
Definition at line 57 of file thread_pool.h.
58 {
59 typedef typename std::result_of<F(Args...)>
::type return_type;
60
61 auto future_work = std::bind(std::forward<F>(f), std::forward<Args>(args)...);
62 auto task = std::make_shared<std::packaged_task<return_type ()>>(future_work);
63 auto future_result = task->get_future();
65 return future_result;
66 }
void queue_thunk(std::function< void()>)
References type.
Referenced by Botan::XMSS_PrivateKey::tree_hash().
◆ shutdown()
void Botan::Thread_Pool::shutdown |
( |
| ) |
|
Definition at line 46 of file thread_pool.cpp.
47 {
48 {
49 std::unique_lock<std::mutex> lock(m_mutex);
50
51 if(m_shutdown == true)
52 return;
53
54 m_shutdown = true;
55
56 m_more_tasks.notify_all();
57 }
58
59 for(auto&& thread : m_workers)
60 {
61 thread.join();
62 }
63 m_workers.clear();
64 }
◆ worker_count()
size_t Botan::Thread_Pool::worker_count |
( |
| ) |
const |
|
inline |
The documentation for this class was generated from the following files: