From 49f7d5d530bb5d1e5c1dde3b74a7b410bbf4f31d Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Tue, 19 Oct 2021 08:19:27 -0500 Subject: [PATCH] updated to new Onyx way of doing multi-threaded modules --- build.sh | 1 - site/js/onyx-loader.js | 23 ++++++++++------------- site/js/onyx-thread.js | 2 +- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/build.sh b/build.sh index 6048a03..ed787c1 100755 --- a/build.sh +++ b/build.sh @@ -16,7 +16,6 @@ RUNTIME=js [ ! -z "$CONSOLE" ] && RUNTIME=wasi onyx --no-colors $FLAGS -r $RUNTIME -V \ - --use-post-mvp-features \ --use-multi-threading \ -I $ONYX_MODULE_DIRECTORY \ --doc doc/source_reference \ diff --git a/site/js/onyx-loader.js b/site/js/onyx-loader.js index 017dbbb..e60ae57 100644 --- a/site/js/onyx-loader.js +++ b/site/js/onyx-loader.js @@ -78,9 +78,9 @@ function launch_onyx_program(script_path, call_start) { }); } -function launch_multi_threaded_onyx_program(script_path, data_path, call_start) { - Promise.all([fetch(script_path), fetch(data_path)]) - .then(function(xs) { return Promise.all([xs[0].arrayBuffer(), xs[1].arrayBuffer()]); }) +function launch_multi_threaded_onyx_program(script_path, call_start) { + fetch(script_path) + .then(function(res) { return res.arrayBuffer(); }) .then(function(data) { var import_object = {}; @@ -90,15 +90,12 @@ function launch_multi_threaded_onyx_program(script_path, data_path, call_start) import_object["onyx"] = { memory: new WebAssembly.Memory({ initial: 1024, maximum: 65536, shared: true }) }; window.ONYX_MEMORY = import_object["onyx"]["memory"]; - window.ONYX_BYTES = data[0]; - - WebAssembly.instantiate(data[1], import_object) - .then(function (data_module) { - WebAssembly.instantiate(data[0], import_object) - .then(function (code_module) { - window.ONYX_INSTANCE = code_module.instance; - code_module.instance.exports._start(); - }); + window.ONYX_BYTES = data; + + WebAssembly.instantiate(data, import_object) + .then(function (code_module) { + window.ONYX_INSTANCE = code_module.instance; + code_module.instance.exports._start(); }); }); } @@ -109,7 +106,7 @@ window.onload = function() { for (var i = 0; i < script_tags.length; i++) { if (script_tags[i].getAttribute("type") == "application/onyx") { if (script_tags[i].getAttribute("multi-threaded")) { - launch_multi_threaded_onyx_program(script_tags[i].getAttribute("src"), script_tags[i].getAttribute("data"), true); + launch_multi_threaded_onyx_program(script_tags[i].getAttribute("src"), true); } else { launch_onyx_program(script_tags[i].getAttribute("src"), true); } diff --git a/site/js/onyx-thread.js b/site/js/onyx-thread.js index 881b2ee..f58a8fd 100644 --- a/site/js/onyx-thread.js +++ b/site/js/onyx-thread.js @@ -31,7 +31,7 @@ self.onmessage = function (msg) { WebAssembly.instantiate(new Uint8Array(data.wasm_bytes), import_object) .then(function(res) { self.ONYX_MEMORY = data.memory; - + res.instance.exports._thread_start(data.thread_id, data.funcidx, data.dataptr); res.instance.exports._thread_exit(data.thread_id); }); -- 2.25.1