Skip to content

Commit 55db0f9

Browse files
authored
Don't run PThread.initMainThread() on Wasm Workers. Fixes #20279. (#21290)
One could argue we shouldn't even run PThread.initWorker() on WASM_WORKERS or AUDIO_WORKLETS, but looking at the current contents of that function, it should be safe to do so (and may lead to some useful functionality), so leaving that in for now.
1 parent 3249c74 commit 55db0f9

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/library_pthread.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,10 @@ var LibraryPThread = {
9292
#if ASSERTIONS
9393
PThread.debugInit();
9494
#endif
95-
if (ENVIRONMENT_IS_PTHREAD
96-
#if AUDIO_WORKLET
97-
|| ENVIRONMENT_IS_AUDIO_WORKLET
98-
#endif
99-
) {
100-
PThread.initWorker();
101-
} else {
95+
if ({{{ ENVIRONMENT_IS_MAIN_THREAD() }}}) {
10296
PThread.initMainThread();
97+
} else {
98+
PThread.initWorker();
10399
}
104100
},
105101
initMainThread() {

src/parseTools.mjs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,6 +1080,15 @@ function implicitSelf() {
10801080
return ENVIRONMENT.includes('node') ? 'self.' : '';
10811081
}
10821082

1083+
function ENVIRONMENT_IS_MAIN_THREAD() {
1084+
var envs = [];
1085+
if (PTHREADS) envs.push('ENVIRONMENT_IS_PTHREAD');
1086+
if (WASM_WORKERS) envs.push('ENVIRONMENT_IS_WASM_WORKER');
1087+
if (AUDIO_WORKLET) envs.push('ENVIRONMENT_IS_AUDIO_WORKLET');
1088+
if (envs.length == 0) return 'true';
1089+
return '(!(' + envs.join('||') + '))';
1090+
}
1091+
10831092
addToCompileTimeContext({
10841093
ATEXITS,
10851094
ATINITS,
@@ -1097,6 +1106,7 @@ addToCompileTimeContext({
10971106
STACK_ALIGN,
10981107
TARGET_NOT_SUPPORTED,
10991108
WASM_PAGE_SIZE,
1109+
ENVIRONMENT_IS_MAIN_THREAD,
11001110
addAtExit,
11011111
addAtInit,
11021112
addReadyPromiseAssertions,

0 commit comments

Comments
 (0)