线程池修改

This commit is contained in:
fasiondog 2020-04-25 23:55:52 +08:00
parent 044334f451
commit 2b961046a6
2 changed files with 13 additions and 2 deletions

View File

@ -25,6 +25,17 @@ namespace hku {
*/
HKU_API ThreadPool* getGlobalTaskGroup();
template <typename ResultType>
using task_handle = std::future<ResultType>;
/**
*
*/
template <typename FunctionType>
task_handle<typename std::result_of<FunctionType()>::type> addTask(FunctionType f) {
return getGlobalTaskGroup()->submit(f);
}
/*
*
*/

View File

@ -81,7 +81,7 @@ public:
} else {
m_master_work_queue.push(std::move(task));
}
m_cv.notify_one();
m_cv.notify_all();
return res;
}
@ -179,7 +179,7 @@ private:
} else {
// std::this_thread::yield();
std::unique_lock<std::mutex> lk(m_cv_mutex);
m_cv.wait(lk);
m_cv.wait(lk, [=] { return this->m_done || !this->m_master_work_queue.empty(); });
}
}