Move from rvalue arguments in ThreadPool enqueue* methods

This commit is contained in:
Eugene Zhulenev 2018-10-16 16:48:32 -07:00
parent 217d839816
commit 9e96e91936

View File

@ -109,26 +109,30 @@ struct ThreadPoolDevice {
} }
template <class Function, class... Args> template <class Function, class... Args>
EIGEN_STRONG_INLINE Notification* enqueue(Function&& f, Args&&... args) const { EIGEN_STRONG_INLINE Notification* enqueue(Function&& f,
Args&&... args) const {
Notification* n = new Notification(); Notification* n = new Notification();
pool_->Schedule(std::bind(&FunctionWrapperWithNotification<Function, Args...>::run, n, f, args...)); pool_->Schedule(
std::bind(&FunctionWrapperWithNotification<Function, Args...>::run, n,
std::move(f), args...));
return n; return n;
} }
template <class Function, class... Args> template <class Function, class... Args>
EIGEN_STRONG_INLINE void enqueue_with_barrier(Barrier* b, EIGEN_STRONG_INLINE void enqueue_with_barrier(Barrier* b, Function&& f,
Function&& f,
Args&&... args) const { Args&&... args) const {
pool_->Schedule(std::bind( pool_->Schedule(
&FunctionWrapperWithBarrier<Function, Args...>::run, b, f, args...)); std::bind(&FunctionWrapperWithBarrier<Function, Args...>::run, b,
std::move(f), args...));
} }
template <class Function, class... Args> template <class Function, class... Args>
EIGEN_STRONG_INLINE void enqueueNoNotification(Function&& f, Args&&... args) const { EIGEN_STRONG_INLINE void enqueueNoNotification(Function&& f,
Args&&... args) const {
if (sizeof...(args) > 0) { if (sizeof...(args) > 0) {
pool_->Schedule(std::bind(f, args...)); pool_->Schedule(std::bind(std::move(f), args...));
} else { } else {
pool_->Schedule(f); pool_->Schedule(std::move(f));
} }
} }