30#ifndef HORIZON_CORE_MULTITHREADING_WORKERTHREADPOOL_HPP
31#define HORIZON_CORE_MULTITHREADING_WORKERTHREADPOOL_HPP
67 impl = std::move(other.impl);
76 std::unique_ptr<impl_base>
impl;
86 for (
unsigned i = 0; i < thread_count; ++i)
98 for (
unsigned long i = 0; i <
_threads.size(); i++)
103 template<
typename FunctionType>
104 std::future<
typename std::invoke_result<FunctionType()>::type>
107 typedef typename std::invoke_result<FunctionType()>::type result_type;
109 std::packaged_task<result_type()> task(std::move(f));
110 std::future<result_type> res(task.get_future());
119 std::shared_ptr<FunctionWrapper> task;
123 std::this_thread::yield();
Definition: WorkerThreadPool.hpp:40
FunctionWrapper(FunctionWrapper &&other)
Definition: WorkerThreadPool.hpp:61
std::unique_ptr< impl_base > impl
Definition: WorkerThreadPool.hpp:76
FunctionWrapper(F &&f)
Definition: WorkerThreadPool.hpp:55
void call()
Definition: WorkerThreadPool.hpp:59
FunctionWrapper(const FunctionWrapper &)=delete
FunctionWrapper & operator=(FunctionWrapper &&other)
Definition: WorkerThreadPool.hpp:65
FunctionWrapper & operator=(const FunctionWrapper &)=delete
FunctionWrapper(FunctionWrapper &)=delete
void push(T &&new_value)
Definition: ThreadSafeQueue.hpp:90
std::shared_ptr< T > try_pop()
Definition: ThreadSafeQueue.hpp:84
Definition: WorkerThreadPool.hpp:80
WorkerThreadPool(unsigned const thread_count=std::thread::hardware_concurrency())
Definition: WorkerThreadPool.hpp:82
std::future< typename std::invoke_result< FunctionType()>::type > submit(FunctionType f)
Definition: WorkerThreadPool.hpp:105
std::atomic_bool _done
Definition: WorkerThreadPool.hpp:128
~WorkerThreadPool()
Definition: WorkerThreadPool.hpp:94
std::vector< std::thread > _threads
Definition: WorkerThreadPool.hpp:127
void worker_thread()
Definition: WorkerThreadPool.hpp:116
ThreadSafeQueue< FunctionWrapper > _work_queue
Definition: WorkerThreadPool.hpp:129
Definition: WorkerThreadPool.hpp:42
virtual ~impl_base()
Definition: WorkerThreadPool.hpp:44
Definition: WorkerThreadPool.hpp:48
F f
Definition: WorkerThreadPool.hpp:49
impl_type(F &&f_)
Definition: WorkerThreadPool.hpp:50
void call()
Definition: WorkerThreadPool.hpp:51