Skip to content

Commit 53a9937

Browse files
authored
Move WasmFS threading heartbeat to library JS code [NFC] (#19697)
This is consistent with other calls into JS code from WasmFS, and it removes the single EM_ASM from the codebase. Noticed because the EM_ASM caused a test not to pass (see added comment in test code).
1 parent eab65a0 commit 53a9937

File tree

4 files changed

+22
-12
lines changed

4 files changed

+22
-12
lines changed

src/library_sigs.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ sigs = {
414414
_wasmfs_opfs_set_size_access__sig: 'vpijp',
415415
_wasmfs_opfs_set_size_file__sig: 'vpijp',
416416
_wasmfs_opfs_write_access__sig: 'iipii',
417+
_wasmfs_thread_utils_heartbeat__sig: 'vp',
417418
abort__sig: 'v',
418419
alBuffer3f__sig: 'viifff',
419420
alBuffer3i__sig: 'viiiii',

src/library_wasmfs.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,4 +416,15 @@ FS.createPreloadedFile = FS_createPreloadedFile;
416416
_wasmfs_copy_preloaded_file_data: function(index, buffer) {
417417
HEAPU8.set(wasmFSPreloadedFiles[index].fileData, buffer);
418418
},
419+
420+
_wasmfs_thread_utils_heartbeat: (queue) => {
421+
var intervalID =
422+
setInterval(() => {
423+
if (ABORT) {
424+
clearInterval(intervalID);
425+
} else {
426+
_emscripten_proxy_execute_queue(queue);
427+
}
428+
}, 50);
429+
},
419430
});

system/lib/wasmfs/thread_utils.h

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
#include <emscripten/proxying.h>
1414
#include <emscripten/threading.h>
1515

16+
extern "C" {
17+
void _wasmfs_thread_utils_heartbeat(em_proxying_queue* ctx);
18+
}
19+
1620
namespace emscripten {
1721

1822
// Helper class for synchronously proxying work to a dedicated worker thread,
@@ -51,16 +55,7 @@ class ProxyWorker {
5155
//
5256
// Note that this requires adding _emscripten_proxy_execute_queue to
5357
// EXPORTED_FUNCTIONS.
54-
EM_ASM({
55-
var intervalID =
56-
setInterval(() => {
57-
if (ABORT) {
58-
clearInterval(intervalID);
59-
} else {
60-
_emscripten_proxy_execute_queue($0);
61-
}
62-
}, 50);
63-
}, queue.queue);
58+
_wasmfs_thread_utils_heartbeat(queue.queue);
6459

6560
// Sit in the event loop performing work as it comes in.
6661
emscripten_exit_with_live_runtime();

test/test_other.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9079,8 +9079,11 @@ def test_js_optimizer_parse_error(self):
90799079
});
90809080
}
90819081
''')
9082-
stderr = self.expect_fail([EMCC, 'src.c', '-O2'])
9083-
# wasm backend output doesn't have spaces in the EM_ASM function bodies
9082+
stderr = self.expect_fail([EMCC, 'src.c', '-O2'] + self.get_emcc_args())
9083+
# TODO: To make this test work in WasmFS, the constant below must be
9084+
# modified. It is the address in memory of the string constant of the
9085+
# EM_ASM, and WasmFS has its own string constants that cause a
9086+
# difference.
90849087
self.assertContained(('''
90859088
1024: () => { var x = !<->5.; }
90869089
^

0 commit comments

Comments
 (0)