1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-25 10:41:16 +02:00

ThreadPool: Start doing work as soon as work items are enqueued

This commit is contained in:
Eelco Dolstra 2016-04-22 18:19:17 +02:00
parent 58c84cda3b
commit b2ce6fde5a
2 changed files with 84 additions and 59 deletions

View file

@ -15,7 +15,9 @@ class ThreadPool
{
public:
ThreadPool(size_t nrThreads = 0);
ThreadPool(size_t maxThreads = 0);
~ThreadPool();
// FIXME: use std::packaged_task?
typedef std::function<void()> work_t;
@ -34,19 +36,22 @@ public:
private:
size_t nrThreads;
size_t maxThreads;
struct State
{
std::queue<work_t> left;
size_t pending = 0;
std::exception_ptr exception;
std::vector<std::thread> workers;
bool quit = false;
};
Sync<State> state;
Sync<State> state_;
std::condition_variable wakeup;
std::condition_variable work, done;
void workerEntry();
};
}