| 48 | } |
| 49 | template<class Fn, class... Args> |
| 50 | std::future<std::invoke_result_t<Fn, Args...>> enqueue(Fn&& fn, Args&&... args) |
| 51 | { |
| 52 | if (stop) throw std::runtime_error("ThreadPool::enqueue: this thread-pool is stopped"); |
| 53 | auto task = std::make_shared<std::packaged_task<std::invoke_result_t<Fn, Args...>()>>(std::bind(std::forward<Fn>(fn), std::forward<Args>(args)...)); |
| 54 | std::future<std::invoke_result_t<Fn, Args...>> result = task->get_future(); |
| 55 | { |
| 56 | std::unique_lock<std::mutex> lock(mutex); |
| 57 | queue.emplace([task] { (*task)(); }); |
| 58 | } |
| 59 | condition.notify_one(); |
| 60 | return result; |
| 61 | } |
| 62 | bool stopped() const |
| 63 | { |
| 64 | return stop; |
nothing calls this directly
no outgoing calls
no test coverage detected