emscripten-nthreads.patch 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. diff --git a/thirdparty/embree/common/sys/sysinfo.cpp b/thirdparty/embree/common/sys/sysinfo.cpp
  2. index c98f61fa53..7f7a009a1e 100644
  3. --- a/thirdparty/embree/common/sys/sysinfo.cpp
  4. +++ b/thirdparty/embree/common/sys/sysinfo.cpp
  5. @@ -640,6 +640,12 @@ namespace embree
  6. #if defined(__EMSCRIPTEN__)
  7. #include <emscripten.h>
  8. +
  9. +// -- GODOT start --
  10. +extern "C" {
  11. +extern int godot_js_os_hw_concurrency_get();
  12. +}
  13. +// -- GODOT end --
  14. #endif
  15. namespace embree
  16. @@ -653,21 +659,9 @@ namespace embree
  17. nThreads = sysconf(_SC_NPROCESSORS_ONLN); // does not work in Linux LXC container
  18. assert(nThreads);
  19. #elif defined(__EMSCRIPTEN__)
  20. - // WebAssembly supports pthreads, but not pthread_getaffinity_np. Get the number of logical
  21. - // threads from the browser or Node.js using JavaScript.
  22. - nThreads = MAIN_THREAD_EM_ASM_INT({
  23. - const isBrowser = typeof window !== 'undefined';
  24. - const isNode = typeof process !== 'undefined' && process.versions != null &&
  25. - process.versions.node != null;
  26. - if (isBrowser) {
  27. - // Return 1 if the browser does not expose hardwareConcurrency.
  28. - return window.navigator.hardwareConcurrency || 1;
  29. - } else if (isNode) {
  30. - return require('os').cpus().length;
  31. - } else {
  32. - return 1;
  33. - }
  34. - });
  35. + // -- GODOT start --
  36. + nThreads = godot_js_os_hw_concurrency_get();
  37. + // -- GODOT end --
  38. #else
  39. cpu_set_t set;
  40. if (pthread_getaffinity_np(pthread_self(), sizeof(set), &set) == 0)