aboutsummaryrefslogtreecommitdiff
path: root/src/common/util.cpp
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2016-04-28 20:25:33 +0100
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2016-04-28 20:33:59 +0100
commit513a658c87b5fa23533a6b6db36e6d36af6a861d (patch)
treeaca5ae90aec55ec7495d3f5faa9c6b3904b279c6 /src/common/util.cpp
parentMerge pull request #823 (diff)
downloadmonero-513a658c87b5fa23533a6b6db36e6d36af6a861d.tar.xz
add a --max-concurrency flag
It sets the max number of threads to use for a parallel job. This is different that the number of total threads, since monero binaries typically start a lot of them.
Diffstat (limited to '')
-rw-r--r--src/common/util.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/common/util.cpp b/src/common/util.cpp
index 2337f5766..a53a9be52 100644
--- a/src/common/util.cpp
+++ b/src/common/util.cpp
@@ -422,4 +422,27 @@ std::string get_nix_version_display_string()
umask(mode);
#endif
}
+
+ namespace
+ {
+ boost::mutex max_concurrency_lock;
+ unsigned max_concurrency = boost::thread::hardware_concurrency();
+ }
+
+ void set_max_concurrency(unsigned n)
+ {
+ if (n < 1)
+ n = boost::thread::hardware_concurrency();
+ unsigned hwc = boost::thread::hardware_concurrency();
+ if (n > hwc)
+ n = hwc;
+ boost::lock_guard<boost::mutex> lock(max_concurrency_lock);
+ max_concurrency = n;
+ }
+
+ unsigned get_max_concurrency()
+ {
+ boost::lock_guard<boost::mutex> lock(max_concurrency_lock);
+ return max_concurrency;
+ }
}