Use `__proxy` mechanism for kill/cancelThread. NFC
This was noticed while working on #18376
diff --git a/src/library_pthread.js b/src/library_pthread.js
index 83d9900..a51b837 100644
--- a/src/library_pthread.js
+++ b/src/library_pthread.js
@@ -29,8 +29,8 @@
var LibraryPThread = {
$PThread__postset: 'PThread.init();',
$PThread__deps: ['_emscripten_thread_init',
- '$killThread',
- '$cancelThread', '$cleanupThread', '$zeroMemory',
+ '$zeroMemory',
+ '$cleanupThread',
'$spawnThread',
'_emscripten_thread_free_data',
'exit',
@@ -267,10 +267,6 @@
spawnThread(d);
} else if (cmd === 'cleanupThread') {
cleanupThread(d['thread']);
- } else if (cmd === 'killThread') {
- killThread(d['thread']);
- } else if (cmd === 'cancelThread') {
- cancelThread(d['thread']);
} else if (cmd === 'loaded') {
worker.loaded = true;
#if ENVIRONMENT_MAY_BE_NODE
@@ -533,6 +529,9 @@
// entry point, calls pthread_exit, or acts upon a cancellation.
// Detached threads are responsible for calling this themselves,
// otherwise pthread_join is responsible for calling this.
+ // Note: we can't use the 'async' proxy mechanism here since this can be
+ // called from _emscripten_thread_exit after the current thread is been
+ // destroyed (i.e. we can't call back into native code at this point).
if (!ENVIRONMENT_IS_PTHREAD) cleanupThread(thread);
else postMessage({ 'cmd': 'cleanupThread', 'thread': thread });
},
@@ -866,14 +865,15 @@
#endif
},
- __pthread_kill_js__deps: ['emscripten_main_browser_thread_id'],
+ __pthread_kill_js__deps: ['emscripten_main_browser_thread_id',
+ '$cancelThread',
+ '$killThread'],
+ __pthread_kill_js__proxy: 'async',
__pthread_kill_js: function(thread, signal) {
if (signal === {{{ cDefine('SIGCANCEL') }}}) { // Used by pthread_cancel in musl
- if (!ENVIRONMENT_IS_PTHREAD) cancelThread(thread);
- else postMessage({ 'cmd': 'cancelThread', 'thread': thread });
+ cancelThread(thread);
} else {
- if (!ENVIRONMENT_IS_PTHREAD) killThread(thread);
- else postMessage({ 'cmd': 'killThread', 'thread': thread });
+ killThread(thread);
}
return 0;
},
diff --git a/test/other/metadce/test_metadce_minimal_pthreads.jssize b/test/other/metadce/test_metadce_minimal_pthreads.jssize
index 84641cd..8af5661 100644
--- a/test/other/metadce/test_metadce_minimal_pthreads.jssize
+++ b/test/other/metadce/test_metadce_minimal_pthreads.jssize
@@ -1 +1 @@
-16064
+15881