9#include <condition_variable>
11#include "../third/Xulog/logs/Xulog.h"
18 using ptr = std::shared_ptr<threadpool>;
19 using Functor = std::function<void(
void)>;
22 for (
int i = 0; i < thr_count; i++)
40 template <
typename F,
typename... Args>
41 auto push(F &&func, Args &&...args) -> std::future<
decltype(func(args...))>
44 using return_type =
decltype(func(args...));
45 auto tmp_func = std::bind(std::forward<F>(func), std::forward<Args>(args)...);
46 auto task = std::make_shared<std::packaged_task<return_type()>>(tmp_func);
47 std::future<return_type> fu = task->get_future();
50 std::unique_lock<std::mutex> lock(
_mutex);
67 std::vector<Functor> tmp_taskpool;
70 std::unique_lock<std::mutex> lock(
_mutex);
72 _cv.wait(lock, [
this]()
78 for (
auto &task : tmp_taskpool)
89 std::condition_variable
_cv;
Definition threadpool.hpp:16
std::atomic< bool > _stop
Definition threadpool.hpp:86
std::vector< Functor > _taskpool
Definition threadpool.hpp:87
std::shared_ptr< threadpool > ptr
Definition threadpool.hpp:18
void stop()
Definition threadpool.hpp:29
std::vector< std::thread > _threads
Definition threadpool.hpp:90
auto push(F &&func, Args &&...args) -> std::future< decltype(func(args...))>
Definition threadpool.hpp:41
std::mutex _mutex
Definition threadpool.hpp:88
std::condition_variable _cv
Definition threadpool.hpp:89
std::function< void(void)> Functor
Definition threadpool.hpp:19
void entry()
Definition threadpool.hpp:61
threadpool(int thr_count=1)
Definition threadpool.hpp:20
~threadpool()
Definition threadpool.hpp:25
Definition channel.hpp:22