summaryrefslogtreecommitdiff
path: root/src/support/threads.cpp
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2016-06-01 16:19:22 -0700
committerAlon Zakai <alonzakai@gmail.com>2016-06-02 16:06:56 -0700
commitbed10e24a9a1818e8583a1f3b30a6dfdd3b57bfa (patch)
tree10cb9bc445c0cf54804ef52f86aba2c4a4c817ca /src/support/threads.cpp
parentc8a57dee5e9c99c51433f3d08da3edc2aadb0140 (diff)
downloadbinaryen-bed10e24a9a1818e8583a1f3b30a6dfdd3b57bfa.tar.gz
binaryen-bed10e24a9a1818e8583a1f3b30a6dfdd3b57bfa.tar.bz2
binaryen-bed10e24a9a1818e8583a1f3b30a6dfdd3b57bfa.zip
refactor a getNumCores method
Diffstat (limited to 'src/support/threads.cpp')
-rw-r--r--src/support/threads.cpp14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/support/threads.cpp b/src/support/threads.cpp
index 2c2db1997..4830cd092 100644
--- a/src/support/threads.cpp
+++ b/src/support/threads.cpp
@@ -116,14 +116,18 @@ void ThreadPool::initialize(size_t num) {
DEBUG_POOL("initialize() is done\n");
}
+size_t ThreadPool::getNumCores() {
+ size_t num = std::max(1U, std::thread::hardware_concurrency());
+ if (getenv("BINARYEN_CORES")) {
+ num = std::stoi(getenv("BINARYEN_CORES"));
+ }
+ return num;
+}
+
ThreadPool* ThreadPool::get() {
if (!pool) {
- size_t num = std::max(1U, std::thread::hardware_concurrency());
- if (getenv("BINARYEN_CORES")) {
- num = std::stoi(getenv("BINARYEN_CORES"));
- }
pool = std::unique_ptr<ThreadPool>(new ThreadPool());
- pool->initialize(num);
+ pool->initialize(getNumCores());
}
return pool.get();
}