From: Brendan Hansen Date: Mon, 22 Nov 2021 05:13:18 +0000 (-0600) Subject: starting on multi-threading X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=ed347f28f619f10e55d6ddfe052c02078f2bed6c;p=heartbreak.git starting on multi-threading --- diff --git a/docs/todo.md b/docs/todo.md index 65928c2..ab93114 100644 --- a/docs/todo.md +++ b/docs/todo.md @@ -51,3 +51,10 @@ More graphics: [ ] Canvases (renderable surfaces) [ ] Meshes [ ] Shaders + + + +Threading: +The default Wasmer engine supports multi-threading, however, the abi for threading needs to be +defined. To steal from the Onyx ABI, heartbreak needs to detect if the module wants to import +or export a memory. then a "spawn thread" and "kill thread" interface needs to be defined. \ No newline at end of file diff --git a/src/heartbreak.c b/src/heartbreak.c index 181f7f5..6e95493 100644 --- a/src/heartbreak.c +++ b/src/heartbreak.c @@ -23,6 +23,10 @@ #include "wasm.h" #include "wasmer.h" +#define HEARTBREAK_WASM_MEMORY_NAME "memory" +#define HEARTBREAK_WASM_FUNCTION_TABLE_NAME "func_table" +#define HEARTBREAK_WASM_START_FUNCTION_NAME "_start" + GLFWwindow* glfw_window = NULL; ImmediateRenderer renderer; wasm_module_t* wasm_module; @@ -65,11 +69,8 @@ void build_heartbreak_imports(WasmFuncDefinition*** out_wfds, i32* out_count) { *out_count = count; } -#define HEARTBREAK_WASM_MEMORY_NAME "memory" -#define HEARTBREAK_WASM_FUNCTION_TABLE_NAME "func_table" -#define HEARTBREAK_WASM_START_FUNCTION_NAME "_start" - void run_wasm_file(bh_buffer wasm_bytes) { + wasmer_features_t* features = NULL; wasm_config_t* config = NULL; wasi_config_t* wasi_config = NULL; wasi_env_t* wasi_env = NULL; @@ -85,6 +86,10 @@ void run_wasm_file(bh_buffer wasm_bytes) { wasm_config_set_compiler(config, LLVM); } + features = wasmer_features_new(); + wasmer_features_threads(features, 1); + wasm_config_set_features(config, features); + wasi_config = wasi_config_new("onyx"); wasi_config_preopen_dir(wasi_config, "./");