diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2016-04-22 18:19:17 +0200 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2016-04-22 18:19:17 +0200 |
commit | b2ce6fde5a46b0ebf32139cbbfe97294120f3a90 (patch) | |
tree | 7f1104a89f6f83681368d4cfe0c9f87ab944ab38 /src/libutil/thread-pool.hh | |
parent | 58c84cda3bdf537dd68ecf5c6bfeb7e942472396 (diff) |
ThreadPool: Start doing work as soon as work items are enqueued
Diffstat (limited to 'src/libutil/thread-pool.hh')
-rw-r--r-- | src/libutil/thread-pool.hh | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/libutil/thread-pool.hh b/src/libutil/thread-pool.hh index 77641d88b..939bcf1ef 100644 --- a/src/libutil/thread-pool.hh +++ b/src/libutil/thread-pool.hh @@ -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(); }; } |