@@ -75,7 +75,7 @@ var LibraryPThread = {
75
75
) {
76
76
t = _pthread_self ( ) ;
77
77
}
78
- return 'w:' + ( Module [ ' workerID' ] || 0 ) + ',t:' + ptrToString ( t ) + ': ' ;
78
+ return 'w:' + ( workerID || 0 ) + ',t:' + ptrToString ( t ) + ': ' ;
79
79
}
80
80
81
81
// Prefix all err()/dbg() messages with the calling thread ID.
@@ -127,16 +127,6 @@ var LibraryPThread = {
127
127
} ,
128
128
129
129
initWorker ( ) {
130
- #if MAYBE_CLOSURE_COMPILER
131
- // worker.js is not compiled together with us, and must access certain
132
- // things.
133
- PThread [ 'receiveObjectTransfer' ] = PThread . receiveObjectTransfer ;
134
- PThread [ 'threadInitTLS' ] = PThread . threadInitTLS ;
135
- #if ! MINIMAL_RUNTIME
136
- PThread [ 'setExitStatus' ] = PThread . setExitStatus ;
137
- #endif
138
- #endif
139
-
140
130
#if isSymbolNeeded ( '$noExitRuntime' )
141
131
// The default behaviour for pthreads is always to exit once they return
142
132
// from their entry point (or call pthread_exit). If we set noExitRuntime
@@ -440,34 +430,47 @@ var LibraryPThread = {
440
430
// Creates a new web Worker and places it in the unused worker pool to wait for its use.
441
431
allocateUnusedWorker ( ) {
442
432
var worker ;
433
+ var workerOptions = {
434
+ { { { EXPORT_ES6 ? "type: 'module'," : "" } } }
435
+ #if ENVIRONMENT_MAY_BE_NODE
436
+ 'workerData' : 'pthread' ,
437
+ #endif
438
+ } ;
443
439
#if MINIMAL_RUNTIME
444
440
var pthreadMainJs = Module [ 'worker' ] ;
445
441
#else
446
442
#if EXPORT_ES6 && USE_ES6_IMPORT_META
447
443
// If we're using module output and there's no explicit override, use bundler-friendly pattern.
448
444
if ( ! Module [ 'locateFile' ] ) {
449
445
#if PTHREADS_DEBUG
450
- dbg ( 'Allocating a new web worker from ' + new URL ( '{{{ PTHREAD_WORKER_FILE }}}' , import . meta. url ) ) ;
446
+ dbg ( 'Allocating a new web worker from ' + import . meta. url ) ;
451
447
#endif
452
448
#if TRUSTED_TYPES
453
449
// Use Trusted Types compatible wrappers.
454
450
if ( typeof trustedTypes != 'undefined' && trustedTypes . createPolicy ) {
455
451
var p = trustedTypes . createPolicy (
456
452
'emscripten#workerPolicy1' ,
457
453
{
458
- createScriptURL : ( ignored ) => new URL ( '{{{ PTHREAD_WORKER_FILE }}}' , import . meta. url ) ;
454
+ createScriptURL : ( ignored ) => new URL ( import . meta. url ) ;
459
455
}
460
456
) ;
461
- worker = new Worker ( p . createScriptURL ( 'ignored' ) , { type : 'module' } ) ;
457
+ worker = new Worker ( p . createScriptURL ( 'ignored' ) , workerOptions ) ;
462
458
} else
463
459
#endif
464
- worker = new Worker ( new URL ( '{{{ PTHREAD_WORKER_FILE }}}' , import . meta. url ) , { type : 'module' } ) ;
460
+ worker = new Worker ( new URL ( import . meta. url ) , workerOptions ) ;
465
461
} else {
466
462
#endif
467
463
// Allow HTML module to configure the location where the 'worker.js' file will be loaded from,
468
464
// via Module.locateFile() function. If not specified, then the default URL 'worker.js' relative
469
465
// to the main html file is loaded.
470
- var pthreadMainJs = locateFile ( '{{{ PTHREAD_WORKER_FILE }}}' ) ;
466
+ var pthreadMainJs = locateFile ( '{{{ TARGET_JS_NAME }}}' ) ;
467
+ #if ENVIRONMENT_MAY_BE_WEB
468
+ // On the web we use a URL parameter to determine if we are running a
469
+ // pthread or not.
470
+ if ( ENVIRONMENT_IS_WEB ) {
471
+ pthreadMainJs += '?pthread=1' ;
472
+ }
473
+ #endif
471
474
#endif
472
475
#if PTHREADS_DEBUG
473
476
dbg ( `Allocating a new web worker from ${pthreadMainJs } `) ;
@@ -476,10 +479,10 @@ var LibraryPThread = {
476
479
// Use Trusted Types compatible wrappers.
477
480
if ( typeof trustedTypes != 'undefined ' && trustedTypes . createPolicy ) {
478
481
var p = trustedTypes . createPolicy ( 'emscripten#workerPolicy2' , { createScriptURL : ( ignored ) => pthreadMainJs } ) ;
479
- worker = new Worker ( p . createScriptURL ( 'ignored' ) { { { EXPORT_ES6 ? ", {type: 'module'}" : '' } } } ) ;
482
+ worker = new Worker ( p . createScriptURL ( 'ignored' ) , workerOptions ) ;
480
483
} else
481
484
#endif
482
- worker = new Worker ( pthreadMainJs { { { EXPORT_ES6 ? ", {type: 'module'}" : '' } } } ) ;
485
+ worker = new Worker ( pthreadMainJs , workerOptions ) ;
483
486
#if EXPORT_ES6 && USE_ES6_IMPORT_META
484
487
}
485
488
#endif
@@ -606,6 +609,9 @@ var LibraryPThread = {
606
609
607
610
#if MAIN_MODULE
608
611
$registerTLSInit : ( tlsInitFunc , moduleExports , metadata ) => {
612
+ #if ASSERTIONS
613
+ assert ( tlsInitFunc ) ;
614
+ #endif
609
615
#if DYLINK_DEBUG
610
616
dbg ( "registerTLSInit: " + tlsInitFunc ) ;
611
617
#endif
0 commit comments