From b2ce6fde5a46b0ebf32139cbbfe97294120f3a90 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 22 Apr 2016 18:19:17 +0200 Subject: ThreadPool: Start doing work as soon as work items are enqueued --- src/libutil/thread-pool.hh | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/libutil/thread-pool.hh') 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 work_t; @@ -34,19 +36,22 @@ public: private: - size_t nrThreads; + size_t maxThreads; struct State { std::queue left; size_t pending = 0; std::exception_ptr exception; + std::vector workers; + bool quit = false; }; - Sync state; + Sync state_; - std::condition_variable wakeup; + std::condition_variable work, done; + void workerEntry(); }; } -- cgit v1.2.3