Skip to content

Commit

Permalink
Use rest and spread operators in multi-threaded code. NFC (#21270)
Browse files Browse the repository at this point in the history
These operators are available everywhere that we can run mutli-threaded
code.
  • Loading branch information
sbc100 authored Feb 6, 2024
1 parent 3495d9a commit 31e823d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -2911,7 +2911,7 @@ addToLibrary({
// code paths as similar as possible on both sides.)
// -1 - code is the encoding of a proxied EM_ASM, as a negative number
// (positive numbers are non-EM_ASM calls).
return proxyToMainThread.apply(null, [-1 - code, sync].concat(args));
return proxyToMainThread(-1 - code, sync, ...args);
}
#endif
#if ASSERTIONS
Expand Down
16 changes: 6 additions & 10 deletions src/library_pthread.js
Original file line number Diff line number Diff line change
Expand Up @@ -957,21 +957,17 @@ var LibraryPThread = {
#if MEMORY64
// Calls proxyToMainThread but returns a bigint rather than a number
$proxyToMainThreadPtr__deps: ['$proxyToMainThread'],
$proxyToMainThreadPtr: function() {
return BigInt(proxyToMainThread.apply(null, arguments));
},
$proxyToMainThreadPtr: (...args) => BigInt(proxyToMainThread(...args)),
#endif
$proxyToMainThread__deps: ['$withStackSave', '_emscripten_run_on_main_thread_js'].concat(i53ConversionDeps),
$proxyToMainThread__docs: '/** @type{function(number, (number|boolean), ...(number|boolean))} */',
$proxyToMainThread: function(index, sync) {
$proxyToMainThread__docs: '/** @type{function(number, (number|boolean), ...number)} */',
$proxyToMainThread: (index, sync, ...callArgs) => {
// Additional arguments are passed after those two, which are the actual
// function arguments.
// The serialization buffer contains the number of call params, and then
// all the args here.
// We also pass 'sync' to C separately, since C needs to look at it.
var numCallArgs = arguments.length - 2;
var outerArgs = arguments;
// Allocate a buffer, which will be copied by the C code.
return withStackSave(() => {
// First passed parameter specifies the number of arguments to the function.
Expand All @@ -980,11 +976,11 @@ var LibraryPThread = {
// type info here). To do that, add a "prefix" before each value that
// indicates if it is a BigInt, which effectively doubles the number of
// values we serialize for proxying. TODO: pack this?
var serializedNumCallArgs = numCallArgs {{{ WASM_BIGINT ? "* 2" : "" }}};
var serializedNumCallArgs = callArgs.length {{{ WASM_BIGINT ? "* 2" : "" }}};
var args = stackAlloc(serializedNumCallArgs * 8);
var b = {{{ getHeapOffset('args', 'i64') }}};
for (var i = 0; i < numCallArgs; i++) {
var arg = outerArgs[2 + i];
for (var i = 0; i < callArgs.length; i++) {
var arg = callArgs[i];
#if WASM_BIGINT
if (typeof arg == 'bigint') {
// The prefix is non-zero to indicate a bigint.
Expand Down
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_minimal_pthreads.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4923
4920
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_minimal_pthreads.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
13664
13635

0 comments on commit 31e823d

Please sign in to comment.