Skip to content

Commit

Permalink
[Emscripten port] Fix core count logic for Emscripten+pthreads (#6350)
Browse files Browse the repository at this point in the history
Before this all Emscripten builds would use 1 core, but it is important to
allow pthreads builds there to use more.
  • Loading branch information
kripken authored Feb 27, 2024
1 parent 703ff00 commit 55c2062
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/support/threads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 55c2062

Please sign in to comment.