Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/UtilsCtrl/ThreadPool/UThreadPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ class UThreadPool : public UThreadObject {
* @return
*/
template<typename FunctionType>
auto commit(const FunctionType& func,
auto commit(FunctionType&& func,
CIndex index = CGRAPH_DEFAULT_TASK_STRATEGY)
-> std::future<decltype(std::declval<FunctionType>()())>;
-> std::future<decltype(std::declval<typename std::decay<FunctionType>::type>()())>;

/**
* 鍚戠壒瀹氱殑绾跨▼id涓紝鎻愪氦浠诲姟淇℃伅
Expand All @@ -84,8 +84,8 @@ class UThreadPool : public UThreadObject {
* @return
*/
template<typename FunctionType>
auto commitWithTid(const FunctionType& func, CIndex tid, CBool enable, CBool lockable)
-> std::future<decltype(std::declval<FunctionType>()())>;
auto commitWithTid(FunctionType&& func, CIndex tid, CBool enable, CBool lockable)
-> std::future<decltype(std::declval<typename std::decay<FunctionType>::type>()())>;

/**
* 鏍规嵁浼樺厛绾э紝鎵ц浠诲姟
Expand Down
16 changes: 8 additions & 8 deletions src/UtilsCtrl/ThreadPool/UThreadPool.inl
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@

CGRAPH_NAMESPACE_BEGIN
template<typename FunctionType>
auto UThreadPool::commit(const FunctionType& func, CIndex index)
-> std::future<decltype(std::declval<FunctionType>()())> {
using ResultType = decltype(std::declval<FunctionType>()());
auto UThreadPool::commit(FunctionType&& func, CIndex index)
-> std::future<decltype(std::declval<typename std::decay<FunctionType>::type>()())> {
using ResultType = decltype(std::declval<typename std::decay<FunctionType>::type>()());

std::packaged_task<ResultType()> task(func);
std::packaged_task<ResultType()> task(std::forward<FunctionType>(func));
std::future<ResultType> result(task.get_future());

execute(std::move(task), index);
Expand All @@ -26,10 +26,10 @@ auto UThreadPool::commit(const FunctionType& func, CIndex index)


template<typename FunctionType>
auto UThreadPool::commitWithTid(const FunctionType& func, CIndex tid, CBool enable, CBool lockable)
-> std::future<decltype(std::declval<FunctionType>()())> {
using ResultType = decltype(std::declval<FunctionType>()());
std::packaged_task<ResultType()> task(std::move(func));
auto UThreadPool::commitWithTid(FunctionType&& func, CIndex tid, CBool enable, CBool lockable)
-> std::future<decltype(std::declval<typename std::decay<FunctionType>::type>()())> {
using ResultType = decltype(std::declval<typename std::decay<FunctionType>::type>()());
std::packaged_task<ResultType()> task(std::forward<FunctionType>(func));
std::future<ResultType> result(task.get_future());

executeWithTid(std::move(task), tid, enable, lockable);
Expand Down
Loading