MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / run

Function run

examples/threads.c:60–122  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

58} thread_args;
59
60void *run(void *args_abs) {
61 thread_args *args = (thread_args *)args_abs;
62
63 // Rereate store and module.
64 own wasm_store_t *store = wasm_store_new(args->engine);
65 own wasm_module_t *module = wasm_module_obtain(store, args->module);
66
67 // Run the example N times.
68 for (int i = 0; i < N_REPS; ++i) {
69 usleep(100000);
70
71 // Create imports.
72 own wasm_functype_t *func_type = wasm_functype_new_0_0();
73 own wasm_func_t *func = wasm_func_new(store, func_type, callback);
74 wasm_functype_delete(func_type);
75
76 // Instantiate.
77 wasm_extern_t *imports[] = {
78 wasm_func_as_extern(func),
79 };
80 wasm_extern_vec_t imports_vec = WASM_ARRAY_VEC(imports);
81 own wasm_instance_t *instance =
82 wasm_instance_new(store, module, &imports_vec, NULL);
83 if (!instance) {
84 printf("> Error instantiating module!\n");
85 return NULL;
86 }
87
88 wasm_func_delete(func);
89
90 // Extract export.
91 own wasm_extern_vec_t exports;
92 wasm_instance_exports(instance, &exports);
93 if (exports.size == 0) {
94 printf("> Error accessing exports!\n");
95 return NULL;
96 }
97 const wasm_func_t *run_func = wasm_extern_as_func(exports.data[0]);
98 if (run_func == NULL) {
99 printf("> Error accessing export!\n");
100 return NULL;
101 }
102
103 wasm_instance_delete(instance);
104
105 // Call.
106 wasm_val_vec_t args_vec = WASM_EMPTY_VEC;
107 wasm_val_vec_t results_vec = WASM_EMPTY_VEC;
108 if (wasm_func_call(run_func, &args_vec, &results_vec)) {
109 printf("> Error calling function!\n");
110 return NULL;
111 }
112
113 wasm_extern_vec_delete(&exports);
114 }
115
116 wasm_module_delete(module);
117 wasm_store_delete(store);

Callers 2

fmtMethod · 0.50
run_test_inputsFunction · 0.50

Calls 8

wasm_store_newFunction · 0.85
wasm_module_obtainFunction · 0.85
wasm_func_newFunction · 0.85
wasm_func_as_externFunction · 0.85
wasm_instance_newFunction · 0.85
wasm_instance_exportsFunction · 0.85
wasm_extern_as_funcFunction · 0.85
wasm_func_callFunction · 0.85

Tested by

no test coverage detected