7#ifndef BOTAN_THREAD_POOL_H_
8#define BOTAN_THREAD_POOL_H_
10#include <botan/types.h>
11#include <botan/work_executor.h>
29 explicit Joining_Future(std::future<T> future) : m_future(std::move(future)) {}
32 if(m_future.valid()) {
44 if(m_future.valid()) {
47 m_future = std::move(other.m_future);
52 decltype(
auto)
get() {
return m_future.get(); }
54 void wait()
const { m_future.wait(); }
56 bool valid() const noexcept {
return m_future.valid(); }
59 std::future<T> m_future;
84 explicit Thread_Pool(std::optional<size_t> pool_size);
105 size_t worker_count()
const;
117 void set_executor(std::shared_ptr<Work_Executor> executor);
131 void queue_thunk(
const std::function<
void()>& work);
136 template <
class F,
class... Args>
138 using return_type = std::invoke_result_t<F, Args...>;
140 const auto future_work = std::bind(std::forward<F>(f), std::forward<Args>(args)...);
141 const auto task = std::make_shared<std::packaged_task<return_type()>>(future_work);
142 auto future_result = task->get_future();
150 mutable std::mutex m_mutex;
152 std::shared_ptr<Work_Executor> m_executor;
153 size_t m_worker_count;
154 bool m_executor_was_set;
bool valid() const noexcept
Joining_Future(Joining_Future &&) noexcept=default
Joining_Future & operator=(const Joining_Future &)=delete
Joining_Future(std::future< T > future)
Joining_Future(const Joining_Future &)=delete
Thread_Pool(Thread_Pool &&)=delete
Thread_Pool & operator=(Thread_Pool &&)=delete
Thread_Pool(std::optional< size_t > pool_size)
auto run(F &&f, Args &&... args) -> Joining_Future< std::invoke_result_t< F, Args... > >
Thread_Pool(size_t pool_size=0)
void queue_thunk(const std::function< void()> &work)
static Thread_Pool & global_instance()
Thread_Pool & operator=(const Thread_Pool &)=delete
Thread_Pool(const Thread_Pool &)=delete