Skip to content

Commit db6eee4

Browse files
authored
Extract pthreadDetection helper. NFC (emscripten-core#26323)
For parity with emscripten-core#26320
1 parent 1422e34 commit db6eee4

File tree

6 files changed

+20
-11
lines changed

6 files changed

+20
-11
lines changed

src/modularize.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ if (typeof exports === 'object' && typeof module === 'object') {
6464
// when running in MODULARIZE mode we need use this to know if we should
6565
// run the module constructor on startup (true only for pthreads).
6666
#if ENVIRONMENT_MAY_BE_WEB || ENVIRONMENT_MAY_BE_WORKER
67-
var isPthread = globalThis.self?.name?.startsWith('em-pthread');
67+
var isPthread = {{{ pthreadDetection() }}};
6868
#if ENVIRONMENT_MAY_BE_NODE
6969
// In order to support both web and node we also need to detect node here.
7070
var isNode = {{{ nodeDetectionCode() }}};

src/parseTools.mjs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,6 +1167,14 @@ function wasmWorkerDetection() {
11671167
}
11681168
}
11691169

1170+
function pthreadDetection() {
1171+
if (ASSERTIONS) {
1172+
return "globalThis.name?.startsWith('em-pthread')";
1173+
} else {
1174+
return "globalThis.name == 'em-pthread'";
1175+
}
1176+
}
1177+
11701178
function makeExportAliases() {
11711179
var res = ''
11721180
for (var [alias, ex] of Object.entries(nativeAliases)) {
@@ -1253,4 +1261,5 @@ addToCompileTimeContext({
12531261
nodePthreadDetection,
12541262
nodeWWDetection,
12551263
wasmWorkerDetection,
1264+
pthreadDetection,
12561265
});

src/shell.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ var ENVIRONMENT_IS_SHELL = !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_NODE && !ENVIR
9797

9898
// The way we signal to a worker that it is hosting a pthread is to construct
9999
// it with a specific name.
100-
var ENVIRONMENT_IS_PTHREAD = ENVIRONMENT_IS_WORKER && self.name?.startsWith('em-pthread');
100+
var ENVIRONMENT_IS_PTHREAD = ENVIRONMENT_IS_WORKER && {{{ pthreadDetection() }}}
101101

102102
#if MODULARIZE && ASSERTIONS
103103
if (ENVIRONMENT_IS_PTHREAD) {

src/shell_minimal.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ var ENVIRONMENT_IS_WORKER = !!globalThis.WorkerGlobalScope;
143143
#if PTHREADS
144144
// MINIMAL_RUNTIME does not support --proxy-to-worker option, so Worker and Pthread environments
145145
// coincide.
146-
var ENVIRONMENT_IS_PTHREAD = ENVIRONMENT_IS_WORKER && self.name?.startsWith('em-pthread');
146+
var ENVIRONMENT_IS_PTHREAD = ENVIRONMENT_IS_WORKER && {{{ pthreadDetection() }}};
147147

148148
#if !MODULARIZE
149149
// In MODULARIZE mode _scriptName needs to be captured already at the very top of the page immediately when the page is parsed, so it is generated there

test/codesize/test_codesize_minimal_pthreads.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"a.out.js": 7894,
3-
"a.out.js.gz": 3862,
2+
"a.out.js": 7888,
3+
"a.out.js.gz": 3857,
44
"a.out.nodebug.wasm": 19726,
55
"a.out.nodebug.wasm.gz": 9135,
6-
"total": 27620,
7-
"total_gz": 12997,
6+
"total": 27614,
7+
"total_gz": 12992,
88
"sent": [
99
"a (memory)",
1010
"b (emscripten_get_now)",

test/codesize/test_codesize_minimal_pthreads_memgrowth.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"a.out.js": 8316,
3-
"a.out.js.gz": 4063,
2+
"a.out.js": 8310,
3+
"a.out.js.gz": 4061,
44
"a.out.nodebug.wasm": 19727,
55
"a.out.nodebug.wasm.gz": 9137,
6-
"total": 28043,
7-
"total_gz": 13200,
6+
"total": 28037,
7+
"total_gz": 13198,
88
"sent": [
99
"a (memory)",
1010
"b (emscripten_get_now)",

0 commit comments

Comments
 (0)