Skip to content

Commit

Permalink
[Support] Reduce allocations in parallelForEach with move
Browse files Browse the repository at this point in the history
Differential Revision: https://reviews.llvm.org/D126458
  • Loading branch information
nga888 committed May 27, 2022
1 parent a73b50a commit 4290ef5
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions llvm/lib/Support/Parallel.cpp
Expand Up @@ -89,7 +89,7 @@ class ThreadPoolExecutor : public Executor {
void add(std::function<void()> F) override {
{
std::lock_guard<std::mutex> Lock(Mutex);
WorkStack.push(F);
WorkStack.push(std::move(F));
}
Cond.notify_one();
}
Expand All @@ -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();
Expand Down Expand Up @@ -161,7 +161,7 @@ TaskGroup::~TaskGroup() {
void TaskGroup::spawn(std::function<void()> F) {
if (Parallel) {
L.inc();
Executor::getDefaultExecutor()->add([&, F] {
Executor::getDefaultExecutor()->add([&, F = std::move(F)] {
F();
L.dec();
});
Expand Down

0 comments on commit 4290ef5

Please sign in to comment.