Skip to content

Commit beace42

Browse files
authored
Merge pull request NixOS#14458 from NixOS/thread-pool-move
ThreadPool::enqueue(): Use move semantics
2 parents 89fa8c0 + 4a0ccc8 commit beace42

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/libutil/include/nix/util/thread-pool.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public:
3636
/**
3737
* Enqueue a function to be executed by the thread pool.
3838
*/
39-
void enqueue(const work_t & t);
39+
void enqueue(work_t t);
4040

4141
/**
4242
* Execute work items until the queue is empty.

src/libutil/thread-pool.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ void ThreadPool::shutdown()
4141
thr.join();
4242
}
4343

44-
void ThreadPool::enqueue(const work_t & t)
44+
void ThreadPool::enqueue(work_t t)
4545
{
4646
auto state(state_.lock());
4747
if (quit)
4848
throw ThreadPoolShutDown("cannot enqueue a work item while the thread pool is shutting down");
49-
state->pending.push(t);
49+
state->pending.push(std::move(t));
5050
/* Note: process() also executes items, so count it as a worker. */
5151
if (state->pending.size() > state->workers.size() + 1 && state->workers.size() + 1 < maxThreads)
5252
state->workers.emplace_back(&ThreadPool::doWork, this, false);

0 commit comments

Comments
 (0)