diff --git a/ext/native/thread/threadpool.cpp b/ext/native/thread/threadpool.cpp index 558d2d5c30..f821fc121d 100644 --- a/ext/native/thread/threadpool.cpp +++ b/ext/native/thread/threadpool.cpp @@ -17,9 +17,9 @@ WorkerThread::~WorkerThread() { thread->join(); } -void WorkerThread::Process(const std::function& work) { +void WorkerThread::Process(std::function work) { mutex.lock(); - work_ = work; + work_ = std::move(work); jobsTarget = jobsDone + 1; signal.notify_one(); mutex.unlock(); @@ -53,9 +53,9 @@ LoopWorkerThread::LoopWorkerThread() : WorkerThread(true) { while (!started) { }; } -void LoopWorkerThread::Process(const std::function &work, int start, int end) { +void LoopWorkerThread::Process(std::function work, int start, int end) { std::lock_guard guard(mutex); - work_ = work; + work_ = std::move(work); start_ = start; end_ = end; jobsTarget = jobsDone + 1; diff --git a/ext/native/thread/threadpool.h b/ext/native/thread/threadpool.h index 294b2bcac3..ee4bcfef33 100644 --- a/ext/native/thread/threadpool.h +++ b/ext/native/thread/threadpool.h @@ -16,7 +16,7 @@ public: virtual ~WorkerThread(); // submit a new work item - void Process(const std::function& work); + void Process(std::function work); // wait for a submitted work item to be completed void WaitForCompletion(); @@ -42,7 +42,7 @@ private: class LoopWorkerThread final : public WorkerThread { public: LoopWorkerThread(); - void Process(const std::function &work, int start, int end); + void Process(std::function work, int start, int end); private: virtual void WorkFunc() override;