From 1423971189793b46b8b67220a13af97afbe2aaf5 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 22 Sep 2020 15:37:16 -0700 Subject: [PATCH 1/2] cleaner --- src/library_pthread.js | 14 +++++++++++++- src/postamble.js | 12 +----------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/library_pthread.js b/src/library_pthread.js index a7621c1f67bf3..0fe387cc36fd7 100644 --- a/src/library_pthread.js +++ b/src/library_pthread.js @@ -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', @@ -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. diff --git a/src/postamble.js b/src/postamble.js index 72c6ec5764bf9..157581ece8378 100644 --- a/src/postamble.js +++ b/src/postamble.js @@ -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(); From 34007ae084642e6a5e8fe52c3ff142a84d1e7d98 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 22 Sep 2020 15:46:20 -0700 Subject: [PATCH 2/2] minimal runtime too --- src/postamble_minimal.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/postamble_minimal.js b/src/postamble_minimal.js index 77e5ffbc4b85d..4da7dd814f83f 100644 --- a/src/postamble_minimal.js +++ b/src/postamble_minimal.js @@ -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);