From 2914a99511a5362b5a9b516723d5233d2b93bf8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jukka=20Jyl=C3=A4nki?= Date: Wed, 7 Feb 2024 18:02:27 +0200 Subject: [PATCH] Don't run PThread.initMainThread() on Wasm Workers. Fixes #20279. --- src/library_pthread.js | 10 +++------- src/parseTools.js | 9 +++++++++ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/library_pthread.js b/src/library_pthread.js index b1497ff91a10..04b93561a8fd 100644 --- a/src/library_pthread.js +++ b/src/library_pthread.js @@ -92,14 +92,10 @@ var LibraryPThread = { #if ASSERTIONS PThread.debugInit(); #endif - if (ENVIRONMENT_IS_PTHREAD -#if AUDIO_WORKLET - || ENVIRONMENT_IS_AUDIO_WORKLET -#endif - ) { - PThread.initWorker(); - } else { + if ({{{ ENVIRONMENT_IS_MAIN_THREAD() }}}) { PThread.initMainThread(); + } else { + PThread.initWorker(); } }, initMainThread() { diff --git a/src/parseTools.js b/src/parseTools.js index 74137e35fbeb..c951f0dd1ea7 100644 --- a/src/parseTools.js +++ b/src/parseTools.js @@ -1043,3 +1043,12 @@ function getPerformanceNow() { function implicitSelf() { return ENVIRONMENT.includes('node') ? 'self.' : ''; } + +function ENVIRONMENT_IS_MAIN_THREAD() { + var envs = []; + if (USE_PTHREADS) envs.push('ENVIRONMENT_IS_PTHREAD'); + if (WASM_WORKERS) envs.push('ENVIRONMENT_IS_WASM_WORKER'); + if (AUDIO_WORKLET) envs.push('ENVIRONMENT_IS_AUDIO_WORKLET'); + if (envs.length == 0) return 'true'; + return '(!(' + envs.join('||') + '))'; +}