diff --git a/llvm/lib/Support/Parallel.cpp b/llvm/lib/Support/Parallel.cpp index 4977c188f934f..85426847c28c9 100644 --- a/llvm/lib/Support/Parallel.cpp +++ b/llvm/lib/Support/Parallel.cpp @@ -89,7 +89,7 @@ class ThreadPoolExecutor : public Executor { void add(std::function F) override { { std::lock_guard Lock(Mutex); - WorkStack.push(F); + WorkStack.push(std::move(F)); } Cond.notify_one(); } @@ -102,7 +102,7 @@ class ThreadPoolExecutor : public Executor { Cond.wait(Lock, [&] { return Stop || !WorkStack.empty(); }); if (Stop) break; - auto Task = WorkStack.top(); + auto Task = std::move(WorkStack.top()); WorkStack.pop(); Lock.unlock(); Task(); @@ -161,7 +161,7 @@ TaskGroup::~TaskGroup() { void TaskGroup::spawn(std::function F) { if (Parallel) { L.inc(); - Executor::getDefaultExecutor()->add([&, F] { + Executor::getDefaultExecutor()->add([&, F = std::move(F)] { F(); L.dec(); });