summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2024-02-26 17:13:25 -0800
committerGitHub <noreply@github.com>2024-02-26 17:13:25 -0800
commit55c206216ea93bd84de8f68b81fd903724006b50 (patch)
treef4dfbc9ffa9c2e2685fc96534522668ca44f36a6
parent703ff000264a959f853a1514915e3509d5497e25 (diff)
downloadbinaryen-55c206216ea93bd84de8f68b81fd903724006b50.tar.gz
binaryen-55c206216ea93bd84de8f68b81fd903724006b50.tar.bz2
binaryen-55c206216ea93bd84de8f68b81fd903724006b50.zip
[Emscripten port] Fix core count logic for Emscripten+pthreads (#6350)
Before this all Emscripten builds would use 1 core, but it is important to allow pthreads builds there to use more.
-rw-r--r--src/support/threads.cpp8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/support/threads.cpp b/src/support/threads.cpp
index e61769a84..58aa05be4 100644
--- a/src/support/threads.cpp
+++ b/src/support/threads.cpp
@@ -139,15 +139,17 @@ void ThreadPool::initialize(size_t num) {
}
size_t ThreadPool::getNumCores() {
-#ifdef __EMSCRIPTEN__
+#if defined(__EMSCRIPTEN__) && !defined(__EMSCRIPTEN_PTHREADS__)
+ // In an Emscripten build without pthreads support, avoid the overhead of
+ // including support code for the below runtime checks.
return 1;
-#else
+#endif
+
size_t num = std::max(1U, std::thread::hardware_concurrency());
if (getenv("BINARYEN_CORES")) {
num = std::stoi(getenv("BINARYEN_CORES"));
}
return num;
-#endif
}
ThreadPool* ThreadPool::get() {