Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 11 additions & 15 deletions src/parseTools.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -785,24 +785,16 @@ export function modifyJSFunction(text, func) {
}

export function runIfMainThread(text) {
if (WASM_WORKERS && PTHREADS) {
return `if (!ENVIRONMENT_IS_WASM_WORKER && !ENVIRONMENT_IS_PTHREAD) { ${text} }`;
} else if (WASM_WORKERS) {
return `if (!ENVIRONMENT_IS_WASM_WORKER) { ${text} }`;
} else if (PTHREADS) {
return `if (!ENVIRONMENT_IS_PTHREAD) { ${text} }`;
if (WASM_WORKERS || PTHREADS) {
return `if (${ENVIRONMENT_IS_MAIN_THREAD()}) { ${text} }`;
} else {
return text;
}
}

function runIfWorkerThread(text) {
if (WASM_WORKERS && PTHREADS) {
return `if (ENVIRONMENT_IS_WASM_WORKER || ENVIRONMENT_IS_PTHREAD) { ${text} }`;
} else if (WASM_WORKERS) {
return `if (ENVIRONMENT_IS_WASM_WORKER) { ${text} }`;
} else if (PTHREADS) {
return `if (ENVIRONMENT_IS_PTHREAD) { ${text} }`;
if (WASM_WORKERS || PTHREADS) {
return `if (${ENVIRONMENT_IS_WORKER_THREAD()}) { ${text} }`;
} else {
return '';
}
Expand Down Expand Up @@ -1094,12 +1086,15 @@ function implicitSelf() {
}

function ENVIRONMENT_IS_MAIN_THREAD() {
return `(!${ENVIRONMENT_IS_WORKER_THREAD()})`;
}

function ENVIRONMENT_IS_WORKER_THREAD() {
assert(PTHREADS || WASM_WORKERS);
var envs = [];
if (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('||') + '))';
return '(' + envs.join('||') + ')';
}

addToCompileTimeContext({
Expand All @@ -1120,6 +1115,7 @@ addToCompileTimeContext({
TARGET_NOT_SUPPORTED,
WASM_PAGE_SIZE,
ENVIRONMENT_IS_MAIN_THREAD,
ENVIRONMENT_IS_WORKER_THREAD,
addAtExit,
addAtInit,
addReadyPromiseAssertions,
Expand Down
17 changes: 2 additions & 15 deletions src/postamble.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,25 +161,12 @@ function run() {
return;
}

#if WASM_WORKERS
if (ENVIRONMENT_IS_WASM_WORKER) {
#if PTHREADS || WASM_WORKERS
if ({{{ ENVIRONMENT_IS_WORKER_THREAD() }}}) {
#if MODULARIZE
readyPromiseResolve(Module);
#endif // MODULARIZE
return initRuntime();
}
#endif

#if PTHREADS
if (ENVIRONMENT_IS_PTHREAD) {
#if MODULARIZE
// The promise resolve function typically gets called as part of the execution
// of `doRun` below. The workers/pthreads don't execute `doRun` so the
// creation promise can be resolved, marking the pthread-Module as initialized.
readyPromiseResolve(Module);
#endif // MODULARIZE
initRuntime();
startWorker(Module);
return;
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/preamble.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ function initRuntime() {
#endif

#if PTHREADS
if (ENVIRONMENT_IS_PTHREAD) return;
if (ENVIRONMENT_IS_PTHREAD) return startWorker(Module);
#endif

#if STACK_OVERFLOW_CHECK
Expand Down
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_minimal_pthreads.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4208
4209
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_minimal_pthreads.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8703
8716
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably noise, but might be worth seeing why this regressed.

Loading