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.cpp | |
| parent | 6b9d9f56a1c7405a68ab5871d7db02e9d98836d5 (diff) | |
| download | monzero-core-db55263b4c25a5014ce72aa1b601cfdebfe5d176.tar.gz monzero-core-db55263b4c25a5014ce72aa1b601cfdebfe5d176.tar.xz monzero-core-db55263b4c25a5014ce72aa1b601cfdebfe5d176.zip | |
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 'src/common/threadpool.cpp')
| -rw-r--r-- | src/common/threadpool.cpp | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/common/threadpool.cpp b/src/common/threadpool.cpp index 51e071577..fb238dca7 100644 --- a/src/common/threadpool.cpp +++ b/src/common/threadpool.cpp @@ -39,11 +39,11 @@ static __thread int depth = 0; namespace tools { -threadpool::threadpool() : running(true), active(0) { +threadpool::threadpool(unsigned int max_threads) : running(true), active(0) { boost::thread::attributes attrs; attrs.set_stack_size(THREAD_STACK_SIZE); - max = tools::get_max_concurrency(); - size_t i = max; + max = max_threads ? max_threads : tools::get_max_concurrency(); + unsigned int i = max; while(i--) { threads.push_back(boost::thread(attrs, boost::bind(&threadpool::run, this))); } @@ -78,7 +78,7 @@ void threadpool::submit(waiter *obj, std::function<void()> f) { } } -int threadpool::get_max_concurrency() { +unsigned int threadpool::get_max_concurrency() const { return max; } |
