Browse Source

feat: 添加了execute 接口,不获取执行的返回信息,效率提升

ChunelFeng 1 year ago
parent
commit
531b130766
2 changed files with 24 additions and 0 deletions
  1. +10
    -0
      src/UtilsCtrl/ThreadPool/UThreadPool.h
  2. +14
    -0
      src/UtilsCtrl/ThreadPool/UThreadPool.inl

+ 10
- 0
src/UtilsCtrl/ThreadPool/UThreadPool.h View File

@ -102,6 +102,16 @@ public:
CGRAPH_CALLBACK_CONST_FUNCTION_REF onFinished = nullptr);
/**
*
* @tparam FunctionType
* @param task
* @param index
*/
template<typename FunctionType>
void execute(const FunctionType& task,
CIndex index = CGRAPH_DEFAULT_TASK_STRATEGY);
/**
* 线id信息线index信息
* @param tid
* @return

+ 14
- 0
src/UtilsCtrl/ThreadPool/UThreadPool.inl View File

@ -56,6 +56,20 @@ auto UThreadPool::commitWithPriority(const FunctionType& func, int priority)
return result;
}
template<typename FunctionType>
void UThreadPool::execute(const FunctionType& task, CIndex index) {
CIndex realIndex = dispatch(index);
if (realIndex >= 0 && realIndex < config_.default_thread_size_) {
primary_threads_[realIndex]->pushTask(std::move(task));
} else if (CGRAPH_LONG_TIME_TASK_STRATEGY == realIndex) {
priority_task_queue_.push(std::move(task), CGRAPH_LONG_TIME_TASK_STRATEGY);
} else {
// 返回其他结果,放到pool的queue中执行
task_queue_.push(std::move(task));
}
}
CGRAPH_NAMESPACE_END
#endif // CGRAPH_UTHREADPOOL_INL

Loading…
Cancel
Save