mirror of
https://gitee.com/fasiondog/hikyuu.git
synced 2024-12-01 03:18:18 +08:00
线程池修改
This commit is contained in:
parent
044334f451
commit
2b961046a6
@ -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);
|
||||
}
|
||||
|
||||
/*
|
||||
* 内部函数,初始化全局任务组
|
||||
*/
|
||||
|
@ -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(); });
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user