1
1
Fork 0
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:
Eelco Dolstra 2025-11-03 17:27:14 +00:00 committed by GitHub
commit beace42e7a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 3 additions and 3 deletions

View file

@ -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.

View file

@ -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);