Skip to content

Commit

Permalink
[perf] change commit to execute.
Browse files Browse the repository at this point in the history
  • Loading branch information
ChunelFeng committed Aug 11, 2024
1 parent 27c0081 commit e8631d9
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
@Desc:
***************************/

#include <algorithm>

#include "GDynamicEngine.h"

CGRAPH_NAMESPACE_BEGIN
Expand Down Expand Up @@ -147,7 +145,7 @@ CVoid GDynamicEngine::process(GElementPtr element, CBool affinity) {
// 如果 affinity=true,表示用当前的线程,执行这个逻辑。以便增加亲和性
exec();
} else {
thread_pool_->commit(exec, calcIndex(element));
thread_pool_->execute(exec, calcIndex(element));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/UtilsCtrl/ThreadPool/UThreadPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ CVoid UThreadPool::monitor() {

// 如果 primary线程都在执行,则表示忙碌
bool busy = !primary_threads_.empty() && std::all_of(primary_threads_.begin(), primary_threads_.end(),
[](UThreadPrimaryPtr ptr) { return nullptr != ptr && ptr->is_running_; });
[](UThreadPrimaryPtr ptr) { return ptr && ptr->is_running_; });

CGRAPH_LOCK_GUARD lock(st_mutex_);
// 如果忙碌或者priority_task_queue_中有任务,则需要添加 secondary线程
Expand Down
4 changes: 2 additions & 2 deletions src/UtilsCtrl/ThreadPool/UThreadPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ class UThreadPool : public UThreadObject {
* @param index
*/
template<typename FunctionType>
void execute(const FunctionType& task,
CIndex index = CGRAPH_DEFAULT_TASK_STRATEGY);
CVoid execute(const FunctionType& task,
CIndex index = CGRAPH_DEFAULT_TASK_STRATEGY);

/**
* 执行任务组信息
Expand Down
3 changes: 1 addition & 2 deletions src/UtilsCtrl/ThreadPool/UThreadPool.inl
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,13 @@ auto UThreadPool::commitWithPriority(const FunctionType& task, int priority)


template<typename FunctionType>
void UThreadPool::execute(const FunctionType& task, CIndex index) {
CVoid 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));
}
}
Expand Down

0 comments on commit e8631d9

Please sign in to comment.