20 typedef TaskPool::__task __task;
23 std::vector<std::thread> _thread;
25 std::condition_variable _cv;
38 for (
auto &t : _thread) {
39 t = std::thread(&ThreadPool::_main,
this);
52 template<
class Function,
class... Args>
53 auto push(Function &&newTask, Args &&...
args) {
54 std::lock_guard lg(_lock);
55 auto future = TaskPool::push(std::forward<Function>(newTask), std::forward<Args>(
args)...);
61 void pushDelayed(std::pair<__time_point, __task> &&task) {
62 std::lock_guard lg(_lock);
64 TaskPool::pushDelayed(std::move(task));
67 template<
class Function,
class X,
class Y,
class... Args>
68 auto pushDelayed(Function &&newTask, std::chrono::duration<X, Y> duration, Args &&...
args) {
69 std::lock_guard lg(_lock);
70 auto future = TaskPool::pushDelayed(std::forward<Function>(newTask), duration, std::forward<Args>(
args)...);
77 void start(
int threads) {
80 _thread.resize(threads);
82 for (
auto &t : _thread) {
83 t = std::thread(&ThreadPool::_main,
this);
88 std::lock_guard lg(_lock);
95 for (
auto &t : _thread) {
102 platf::set_thread_name(
"TaskPool::worker");
104 if (
auto task = this->pop()) {
107 std::unique_lock uniq_lock(_lock);
117 if (
auto tp = next()) {
118 _cv.wait_until(uniq_lock, *tp);
126 while (
auto task = this->pop()) {