diff options
author | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2018-04-23 18:53:38 +0100 |
---|---|---|
committer | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2018-05-20 12:06:03 +0100 |
commit | db55263b4c25a5014ce72aa1b601cfdebfe5d176 (patch) | |
tree | 4ebe82a6051419dd4f1ba04e62c9a86cfcdaa95b /src/common/threadpool.h | |
parent | Merge pull request #3719 (diff) | |
download | monero-db55263b4c25a5014ce72aa1b601cfdebfe5d176.tar.xz |
threadpool: allow constructing an object, and misc tweaks
use unsigned int to avoid having to range check negative numbers,
use const where possible, don't needlessly create empty objects,
use std::move where possible
Diffstat (limited to '')
-rw-r--r-- | src/common/threadpool.h | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/common/threadpool.h b/src/common/threadpool.h index 34152541c..bf80a87f6 100644 --- a/src/common/threadpool.h +++ b/src/common/threadpool.h @@ -46,6 +46,9 @@ public: static threadpool instance; return instance; } + static threadpool *getNewForUnitTests(unsigned max_threads = 0) { + return new threadpool(max_threads); + } // The waiter lets the caller know when all of its // tasks are completed. @@ -66,11 +69,12 @@ public: // task to finish. void submit(waiter *waiter, std::function<void()> f); - int get_max_concurrency(); + unsigned int get_max_concurrency() const; + + ~threadpool(); private: - threadpool(); - ~threadpool(); + threadpool(unsigned int max_threads = 0); typedef struct entry { waiter *wo; std::function<void()> f; @@ -79,8 +83,8 @@ public: boost::condition_variable has_work; boost::mutex mutex; std::vector<boost::thread> threads; - int active; - int max; + unsigned int active; + unsigned int max; bool running; void run(); }; |