Skip to content

Commit b840dc7

Browse files
authored
Rename internal JS proxying function. NFC (#19945)
I renamed the existing `_emscripten_run_in_main_runtime_thread_js` to the simpler `_emscripten_run_in_main_thread_js` to match other things such as `$proxyToMainThread`. I don't believe is ambiguous. There is no way this function could be referring to the main browser thread and not the main runtime thread since if the main browser thread ever exists in the system it is by definition also the main runtime thread. This change is laying the groundwork for a larger change which to move JS function proxying over to the new proxying system.
1 parent 25bec47 commit b840dc7

File tree

7 files changed

+20
-19
lines changed

7 files changed

+20
-19
lines changed

emcc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1710,7 +1710,7 @@ def setup_pthreads(target):
17101710
'_emscripten_thread_free_data',
17111711
'emscripten_main_runtime_thread_id',
17121712
'emscripten_main_thread_process_queued_calls',
1713-
'_emscripten_run_in_main_runtime_thread_js',
1713+
'_emscripten_run_on_main_thread_js',
17141714
'emscripten_stack_set_limits',
17151715
]
17161716

emscripten.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,7 @@ def create_pointer_conversion_wrappers(metadata):
866866
'__cxa_decrement_exception_refcount': '_p',
867867
'_wasmfs_write_file': '_ppp',
868868
'__dl_seterr': '_pp',
869-
'_emscripten_run_in_main_runtime_thread_js': '___p_',
869+
'_emscripten_run_on_main_thread_js': '___p_',
870870
'_emscripten_proxy_execute_task_queue': '_p',
871871
'_emscripten_thread_exit': '_p',
872872
'_emscripten_thread_init': '_p_____',

src/library_pthread.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -955,7 +955,7 @@ var LibraryPThread = {
955955
_exit(returnCode);
956956
},
957957

958-
$proxyToMainThread__deps: ['$withStackSave', '_emscripten_run_in_main_runtime_thread_js'],
958+
$proxyToMainThread__deps: ['$withStackSave', '_emscripten_run_on_main_thread_js'],
959959
$proxyToMainThread__docs: '/** @type{function(number, (number|boolean), ...(number|boolean))} */',
960960
$proxyToMainThread: function(index, sync) {
961961
// Additional arguments are passed after those two, which are the actual
@@ -998,16 +998,17 @@ var LibraryPThread = {
998998
HEAPF64[b + i] = arg;
999999
#endif
10001000
}
1001-
return __emscripten_run_in_main_runtime_thread_js(index, serializedNumCallArgs, args, sync);
1001+
return __emscripten_run_on_main_thread_js(index, serializedNumCallArgs, args, sync);
10021002
});
10031003
},
10041004

1005-
$emscripten_receive_on_main_thread_js_callArgs: '=[]',
1005+
// Reuse global JS array to avoid creating JS garbage for each proxied call
1006+
$proxiedJSCallArgs: '=[]',
10061007

1007-
emscripten_receive_on_main_thread_js__deps: [
1008+
_emscripten_receive_on_main_thread_js__deps: [
10081009
'$proxyToMainThread',
1009-
'$emscripten_receive_on_main_thread_js_callArgs'],
1010-
emscripten_receive_on_main_thread_js: function(index, callingThread, numCallArgs, args) {
1010+
'$proxiedJSCallArgs'],
1011+
_emscripten_receive_on_main_thread_js: function(index, callingThread, numCallArgs, args) {
10111012
// Sometimes we need to backproxy events to the calling thread (e.g.
10121013
// HTML5 DOM events handlers such as
10131014
// emscripten_set_mousemove_callback()), so keep track in a globally
@@ -1016,19 +1017,19 @@ var LibraryPThread = {
10161017
#if WASM_BIGINT
10171018
numCallArgs /= 2;
10181019
#endif
1019-
emscripten_receive_on_main_thread_js_callArgs.length = numCallArgs;
1020+
proxiedJSCallArgs.length = numCallArgs;
10201021
var b = args >> 3;
10211022
for (var i = 0; i < numCallArgs; i++) {
10221023
#if WASM_BIGINT
10231024
if (HEAP64[b + 2*i]) {
10241025
// It's a BigInt.
1025-
emscripten_receive_on_main_thread_js_callArgs[i] = HEAP64[b + 2*i + 1];
1026+
proxiedJSCallArgs[i] = HEAP64[b + 2*i + 1];
10261027
} else {
10271028
// It's a Number.
1028-
emscripten_receive_on_main_thread_js_callArgs[i] = HEAPF64[b + 2*i + 1];
1029+
proxiedJSCallArgs[i] = HEAPF64[b + 2*i + 1];
10291030
}
10301031
#else
1031-
emscripten_receive_on_main_thread_js_callArgs[i] = HEAPF64[b + i];
1032+
proxiedJSCallArgs[i] = HEAPF64[b + i];
10321033
#endif
10331034
}
10341035
// Proxied JS library funcs are encoded as positive values, and
@@ -1040,9 +1041,9 @@ var LibraryPThread = {
10401041
var func = proxiedFunctionTable[index];
10411042
#endif
10421043
#if ASSERTIONS
1043-
assert(func.length == numCallArgs, 'Call args mismatch in emscripten_receive_on_main_thread_js');
1044+
assert(func.length == numCallArgs, 'Call args mismatch in _emscripten_receive_on_main_thread_js');
10441045
#endif
1045-
return func.apply(null, emscripten_receive_on_main_thread_js_callArgs);
1046+
return func.apply(null, proxiedJSCallArgs);
10461047
},
10471048

10481049
$establishStackSpace__internal: true,

src/library_sigs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ sigs = {
325325
_emscripten_notify_mailbox_postmessage__sig: 'vppp',
326326
_emscripten_push_main_loop_blocker__sig: 'vppp',
327327
_emscripten_push_uncounted_main_loop_blocker__sig: 'vppp',
328+
_emscripten_receive_on_main_thread_js__sig: 'dipip',
328329
_emscripten_set_offscreencanvas_size__sig: 'ipii',
329330
_emscripten_thread_exit_joinable__sig: 'vp',
330331
_emscripten_thread_mailbox_await__sig: 'vp',
@@ -712,7 +713,6 @@ sigs = {
712713
emscripten_promise_resolve__sig: 'vpip',
713714
emscripten_promise_then__sig: 'ppppp',
714715
emscripten_random__sig: 'f',
715-
emscripten_receive_on_main_thread_js__sig: 'dipip',
716716
emscripten_request_animation_frame__sig: 'ipp',
717717
emscripten_request_animation_frame_loop__sig: 'vpp',
718718
emscripten_request_fullscreen__sig: 'ipi',

system/lib/pthread/library_pthread.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ static void _do_call(void* arg) {
188188
break;
189189
case EM_PROXIED_JS_FUNCTION:
190190
q->returnValue.d =
191-
emscripten_receive_on_main_thread_js((intptr_t)q->functionPtr, q->callingThread, q->args[0].i, &q->args[1].d);
191+
_emscripten_receive_on_main_thread_js((intptr_t)q->functionPtr, q->callingThread, q->args[0].i, &q->args[1].d);
192192
break;
193193
case EM_FUNC_SIG_V:
194194
((em_func_v)q->functionPtr)();
@@ -420,7 +420,7 @@ int emscripten_sync_run_in_main_runtime_thread_(EM_FUNC_SIGNATURE sig, void* fun
420420
return q.returnValue.i;
421421
}
422422

423-
double _emscripten_run_in_main_runtime_thread_js(int index, int num_args, int64_t* buffer, int sync) {
423+
double _emscripten_run_on_main_thread_js(int index, int num_args, int64_t* buffer, int sync) {
424424
em_queued_call q;
425425
em_queued_call *c;
426426
if (sync) {

system/lib/pthread/threading_internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,4 @@ int __pthread_create_js(struct __pthread *thread, const pthread_attr_t *attr, vo
167167
int _emscripten_default_pthread_stack_size();
168168
void __set_thread_state(pthread_t ptr, int is_main, int is_runtime, int can_block);
169169

170-
double emscripten_receive_on_main_thread_js(int functionIndex, pthread_t callingThread, int numCallArgs, double* args);
170+
double _emscripten_receive_on_main_thread_js(int functionIndex, pthread_t callingThread, int numCallArgs, double* args);

test/other/metadce/test_metadce_minimal_pthreads.funcs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ $__wasm_init_tls
2525
$_do_call
2626
$_emscripten_check_mailbox
2727
$_emscripten_proxy_main
28-
$_emscripten_run_in_main_runtime_thread_js
28+
$_emscripten_run_on_main_thread_js
2929
$_emscripten_thread_crashed
3030
$_emscripten_thread_exit
3131
$_emscripten_thread_free_data

0 commit comments

Comments
 (0)