Skip to content

Clean up pthread startup code (NFC) #12308

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 23, 2020
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
14 changes: 13 additions & 1 deletion src/library_pthread.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

var LibraryPThread = {
$PThread__postset: 'if (!ENVIRONMENT_IS_PTHREAD) PThread.initMainThreadBlock(); else PThread.initWorker();',
$PThread__postset: 'if (!ENVIRONMENT_IS_PTHREAD) PThread.initMainThreadBlock();',
$PThread__deps: ['$registerPthreadPtr',
'$ERRNO_CODES', 'emscripten_futex_wake', '$killThread',
'$cancelThread', '$cleanupThread',
Expand Down Expand Up @@ -87,6 +87,18 @@ var LibraryPThread = {
_emscripten_register_main_browser_thread_id(PThread.mainThreadBlock);
},
initWorker: function() {
#if EMBIND
// Embind must initialize itself on all threads, as it generates support JS.
Module['___embind_register_native_and_builtin_types']();
#endif // EMBIND
#if MODULARIZE
// The promise resolve function typically gets called as part of the execution
// of the Module `run`. The workers/pthreads don't execute `run` here, they
// call `run` in response to a message at a later time, so the creation
// promise can be resolved, marking the pthread-Module as initialized.
readyPromiseResolve(Module);
#endif // MODULARIZE

#if USE_CLOSURE_COMPILER
// worker.js is not compiled together with us, and must access certain
// things.
Expand Down
12 changes: 1 addition & 11 deletions src/postamble.js
Original file line number Diff line number Diff line change
Expand Up @@ -470,17 +470,7 @@ if (!ENVIRONMENT_IS_PTHREAD) // EXIT_RUNTIME=0 only applies to default behavior
if (!ENVIRONMENT_IS_PTHREAD) {
run();
} else {
#if EMBIND
// Embind must initialize itself on all threads, as it generates support JS.
Module['___embind_register_native_and_builtin_types']();
#endif // EMBIND
#if MODULARIZE
// The promise resolve function typically gets called as part of the execution
// of the Module `run`. The workers/pthreads don't execute `run` here, they
// call `run` in response to a message at a later time, so the creation
// promise can be resolved, marking the pthread-Module as initialized.
readyPromiseResolve(Module);
#endif // MODULARIZE
PThread.initWorker();
}
#else
run();
Expand Down
6 changes: 5 additions & 1 deletion src/postamble_minimal.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ function initRuntime(asm) {
Module['registerPthreadPtr'] = registerPthreadPtr;
Module['_pthread_self'] = _pthread_self;

if (ENVIRONMENT_IS_PTHREAD) return;
if (ENVIRONMENT_IS_PTHREAD) {
PThread.initWorker();
return;
}

// Pass the thread address inside the asm.js scope to store it for fast access that avoids the need for a FFI out.
registerPthreadPtr(PThread.mainThreadBlock, /*isMainBrowserThread=*/!ENVIRONMENT_IS_WORKER, /*isMainRuntimeThread=*/1);
_emscripten_register_main_browser_thread_id(PThread.mainThreadBlock);
Expand Down