From f2cab84b0c7bbd3539fc51152d2ffb2e833518f0 Mon Sep 17 00:00:00 2001 From: Chunel Date: Tue, 11 Aug 2026 22:38:01 +0800 Subject: [PATCH] [perf] optimise thread pool commit func --- src/UtilsCtrl/ThreadPool/UThreadPool.h | 8 ++++---- src/UtilsCtrl/ThreadPool/UThreadPool.inl | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/UtilsCtrl/ThreadPool/UThreadPool.h b/src/UtilsCtrl/ThreadPool/UThreadPool.h index 90533bc9..fac28db3 100644 --- a/src/UtilsCtrl/ThreadPool/UThreadPool.h +++ b/src/UtilsCtrl/ThreadPool/UThreadPool.h @@ -70,9 +70,9 @@ class UThreadPool : public UThreadObject { * @return */ template - auto commit(const FunctionType& func, + auto commit(FunctionType&& func, CIndex index = CGRAPH_DEFAULT_TASK_STRATEGY) - -> std::future()())>; + -> std::future::type>()())>; /** * 向特定的线程id中,提交任务信息 @@ -84,8 +84,8 @@ class UThreadPool : public UThreadObject { * @return */ template - auto commitWithTid(const FunctionType& func, CIndex tid, CBool enable, CBool lockable) - -> std::future()())>; + auto commitWithTid(FunctionType&& func, CIndex tid, CBool enable, CBool lockable) + -> std::future::type>()())>; /** * 根据优先级,执行任务 diff --git a/src/UtilsCtrl/ThreadPool/UThreadPool.inl b/src/UtilsCtrl/ThreadPool/UThreadPool.inl index 3c43e3cb..ef3cb1e5 100644 --- a/src/UtilsCtrl/ThreadPool/UThreadPool.inl +++ b/src/UtilsCtrl/ThreadPool/UThreadPool.inl @@ -13,11 +13,11 @@ CGRAPH_NAMESPACE_BEGIN template -auto UThreadPool::commit(const FunctionType& func, CIndex index) --> std::future()())> { - using ResultType = decltype(std::declval()()); +auto UThreadPool::commit(FunctionType&& func, CIndex index) +-> std::future::type>()())> { + using ResultType = decltype(std::declval::type>()()); - std::packaged_task task(func); + std::packaged_task task(std::forward(func)); std::future result(task.get_future()); execute(std::move(task), index); @@ -26,10 +26,10 @@ auto UThreadPool::commit(const FunctionType& func, CIndex index) template -auto UThreadPool::commitWithTid(const FunctionType& func, CIndex tid, CBool enable, CBool lockable) --> std::future()())> { - using ResultType = decltype(std::declval()()); - std::packaged_task task(std::move(func)); +auto UThreadPool::commitWithTid(FunctionType&& func, CIndex tid, CBool enable, CBool lockable) +-> std::future::type>()())> { + using ResultType = decltype(std::declval::type>()()); + std::packaged_task task(std::forward(func)); std::future result(task.get_future()); executeWithTid(std::move(task), tid, enable, lockable);