Skip to content

Commit

Permalink
Append em-pthread id to the web worker name.
Browse files Browse the repository at this point in the history
Simplifies picking a web worker when using browser debug tools.
  • Loading branch information
Moritz Duge committed Sep 27, 2024
1 parent f508b43 commit cece8ea
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/library_pthread.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ var LibraryPThread = {
#if ENVIRONMENT_MAY_BE_WEB || ENVIRONMENT_MAY_BE_WORKER
// This is the way that we signal to the Web Worker that it is hosting
// a pthread.
'name': 'em-pthread',
'name': 'em-pthread_' + PThread.nextWorkerID,
#endif
};
#if EXPORT_ES6 && USE_ES6_IMPORT_META
Expand Down
2 changes: 1 addition & 1 deletion src/shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ if (Module['ENVIRONMENT']) {

// The way we signal to a worker that it is hosting a pthread is to construct
// it with a specific name.
var ENVIRONMENT_IS_PTHREAD = ENVIRONMENT_IS_WORKER && self.name == 'em-pthread';
var ENVIRONMENT_IS_PTHREAD = ENVIRONMENT_IS_WORKER && self.name.startsWith('em-pthread_');

#if MODULARIZE && ASSERTIONS
if (ENVIRONMENT_IS_PTHREAD) {
Expand Down
2 changes: 1 addition & 1 deletion src/shell_minimal.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ function ready() {
// MINIMAL_RUNTIME does not support --proxy-to-worker option, so Worker and Pthread environments
// coincide.
var ENVIRONMENT_IS_WORKER = typeof importScripts == 'function';
var ENVIRONMENT_IS_PTHREAD = ENVIRONMENT_IS_WORKER && self.name == 'em-pthread';
var ENVIRONMENT_IS_PTHREAD = ENVIRONMENT_IS_WORKER && self.name.startsWith('em-pthread_');

#if !MODULARIZE
// 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
Expand Down
2 changes: 1 addition & 1 deletion tools/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -2445,7 +2445,7 @@ def modularize():
# when running in MODULARIZE mode we need use this to know if we should
# run the module constructor on startup (true only for pthreads).
if settings.ENVIRONMENT_MAY_BE_WEB or settings.ENVIRONMENT_MAY_BE_WORKER:
src += "var isPthread = globalThis.self?.name === 'em-pthread';\n"
src += "var isPthread = globalThis.self?.name.startsWith('em-pthread_');\n"
# In order to support both web and node we also need to detect node here.
if settings.ENVIRONMENT_MAY_BE_NODE:
src += "var isNode = typeof globalThis.process?.versions?.node == 'string';\n"
Expand Down

0 comments on commit cece8ea

Please sign in to comment.