starting on multi-threading
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 22 Nov 2021 05:13:18 +0000 (23:13 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 22 Nov 2021 05:13:18 +0000 (23:13 -0600)
docs/todo.md
src/heartbreak.c

index 65928c214357080a719738ccfa71aeaab4642eb3..ab93114fc524c0082f4318fc5bd79343dd59a3a7 100644 (file)
@@ -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
index 181f7f57f9dac453250e898a6b07cfb005a2e6f9..6e95493e7449eaf91134ac23f0db77a2e4286474 100644 (file)
 #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, "./");