Skip to content

Commit

Permalink
Don't run PThread.initMainThread() on Wasm Workers. Fixes emscripten-…
Browse files Browse the repository at this point in the history
  • Loading branch information
juj committed Feb 7, 2024
1 parent 21f2533 commit 2914a99
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/library_pthread.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
9 changes: 9 additions & 0 deletions src/parseTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('||') + '))';
}

0 comments on commit 2914a99

Please sign in to comment.