mirror of
https://github.com/NixOS/nix.git
synced 2025-11-08 11:36:03 +01:00
ThreadPool::enqueue(): Use move semantics
This avoids a superfluous copy of the work item.
This commit is contained in:
parent
5e025ce940
commit
4a0ccc89d9
2 changed files with 3 additions and 3 deletions
|
|
@ -36,7 +36,7 @@ public:
|
|||
/**
|
||||
* Enqueue a function to be executed by the thread pool.
|
||||
*/
|
||||
void enqueue(const work_t & t);
|
||||
void enqueue(work_t t);
|
||||
|
||||
/**
|
||||
* Execute work items until the queue is empty.
|
||||
|
|
|
|||
|
|
@ -41,12 +41,12 @@ void ThreadPool::shutdown()
|
|||
thr.join();
|
||||
}
|
||||
|
||||
void ThreadPool::enqueue(const work_t & t)
|
||||
void ThreadPool::enqueue(work_t t)
|
||||
{
|
||||
auto state(state_.lock());
|
||||
if (quit)
|
||||
throw ThreadPoolShutDown("cannot enqueue a work item while the thread pool is shutting down");
|
||||
state->pending.push(t);
|
||||
state->pending.push(std::move(t));
|
||||
/* Note: process() also executes items, so count it as a worker. */
|
||||
if (state->pending.size() > state->workers.size() + 1 && state->workers.size() + 1 < maxThreads)
|
||||
state->workers.emplace_back(&ThreadPool::doWork, this, false);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue