13 #ifndef HERMES_THREAD_POOL_H_
14 #define HERMES_THREAD_POOL_H_
16 #include <condition_variable>
30 unsigned num_threads = std::thread::hardware_concurrency()) {
31 while (num_threads--) {
34 std::unique_lock<std::mutex> lock(
mutex);
39 auto task = high_priority ? std::move(
queue_high.front())
62 template <
typename F,
typename R = std::result_of_t<F && ()>>
63 std::future<R>
run(F&& f,
bool high_priority =
false)
const {
64 auto task = std::packaged_task<R()>(std::forward<F>(f));
65 auto future = task.get_future();
67 std::lock_guard<std::mutex> lock(
mutex);
72 queue_high.push(std::packaged_task<
void()>(std::move(task)));
74 queue_low.push(std::packaged_task<
void()>(std::move(task)));
85 std::lock_guard<std::mutex> lock(
mutex);
97 mutable std::queue<std::packaged_task<void()>>
queue_low;
99 mutable std::queue<std::packaged_task<void()>>
queue_high;
Definition: thread_pool.h:26
std::vector< std::thread > threads
Definition: thread_pool.h:95
ThreadPool(unsigned num_threads=std::thread::hardware_concurrency())
Definition: thread_pool.h:29
std::condition_variable condvar
Definition: thread_pool.h:101
std::mutex mutex
Definition: thread_pool.h:100
std::queue< std::packaged_task< void()> > queue_low
Definition: thread_pool.h:97
std::queue< std::packaged_task< void()> > queue_high
Definition: thread_pool.h:99
std::future< R > run(F &&f, bool high_priority=false) const
Definition: thread_pool.h:63
Definition: adapter_utils.cc:35