diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/support/threads.cpp | 14 | ||||
-rw-r--r-- | src/support/threads.h | 3 |
2 files changed, 12 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(); } diff --git a/src/support/threads.h b/src/support/threads.h index 9a43ac699..ea9e53c13 100644 --- a/src/support/threads.h +++ b/src/support/threads.h @@ -79,6 +79,9 @@ private: void initialize(size_t num); public: + // Get the number of cores we can use. + static size_t getNumCores(); + // Get the singleton threadpool. This can return null // if there is just one thread available. static ThreadPool* get(); |