7#include <botan/internal/thread_pool.h>
8#include <botan/internal/os_utils.h>
9#include <botan/exceptn.h>
40 for(
size_t i = 0; i != pool_size; ++i)
42 m_workers.push_back(std::thread(&Thread_Pool::worker_thread,
this));
49 std::unique_lock<std::mutex> lock(m_mutex);
51 if(m_shutdown ==
true)
56 m_more_tasks.notify_all();
59 for(
auto&& thread : m_workers)
68 std::unique_lock<std::mutex> lock(m_mutex);
71 throw Invalid_State(
"Cannot add work after thread pool has shut down");
73 m_tasks.push_back(fn);
74 m_more_tasks.notify_one();
77void Thread_Pool::worker_thread()
81 std::function<void()> task;
84 std::unique_lock<std::mutex> lock(m_mutex);
85 m_more_tasks.wait(lock, [
this]{
return m_shutdown || !m_tasks.empty(); });
95 task = m_tasks.front();
void queue_thunk(std::function< void()>)
Thread_Pool(size_t pool_size=0)
static Thread_Pool & global_instance()
size_t BOTAN_TEST_API get_cpu_available()
size_t read_env_variable_sz(const std::string &var_name, size_t def_value=0)