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