Skip to content

Commit 0b007c2

Browse files
committed
allow loading wasm in threads
1 parent 4ea0687 commit 0b007c2

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

externals/wamr/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,13 @@ set(WAMR_DISABLE_HW_BOUND_CHECK 0)
3939
set(WAMR_DISABLE_STACK_HW_BOUND_CHECK 0)
4040
set(WAMR_DISABLE_WAKEUP_BLOCKING_OP 0)
4141
add_compile_definitions(BUILTIN_LIBC_BUFFERED_PRINTF=1 BUILTIN_LIBC_BUFFERED_PRINT_SIZE=512)
42-
4342
add_compile_definitions("$<$<CONFIG:Debug>:BH_DEBUG=1>")
4443

4544
include("${CMAKE_CURRENT_LIST_DIR}/wamr/build-scripts/runtime_lib.cmake")
4645

4746
file(GLOB_RECURSE iwasm_headers "${CMAKE_CURRENT_LIST_DIR}/wamr/core/*.h")
4847
add_library(iwasm_static STATIC ${WAMR_RUNTIME_LIB_SOURCE} ${iwasm_headers})
4948
target_include_directories(iwasm_static INTERFACE "wamr/core/iwasm/include")
50-
target_link_libraries(iwasm_static INTERFACE ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS})
5149
target_compile_definitions(iwasm_static PUBLIC WASM_RUNTIME_API_EXTERN= WASM_API_EXTERN= COMPILING_WASM_RUNTIME_API=1)
5250

5351
if(MSVC)

sources/libcore/wasm.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ namespace cage
7070
return 0;
7171
}();
7272
(void)dummy;
73+
thread_local int dummy2 = []() -> int
74+
{
75+
if (!wasm_runtime_init_thread_env())
76+
CAGE_THROW_ERROR(Exception, "failed to initialize wasm thread env");
77+
return 0;
78+
}();
79+
(void)dummy2;
7380
}
7481

7582
WasmTypeEnum convert(wasm_valkind_t k)
@@ -188,6 +195,8 @@ namespace cage
188195

189196
WasmInstanceImpl(Holder<WasmModule> &&module_) : module(std::move(module_).cast<WasmModuleImpl>())
190197
{
198+
initialize();
199+
191200
CAGE_ASSERT(module);
192201
String err;
193202
instance = wasm_runtime_instantiate(module->module, 1'000'000, 1'000'000, err.rawData(), err.MaxLength - 100);
@@ -227,6 +236,8 @@ namespace cage
227236

228237
WasmFunctionImpl(WasmInstanceImpl *instance, const String &name) : name(name), instance(instance)
229238
{
239+
CAGE_ASSERT(wasm_runtime_thread_env_inited());
240+
230241
func = wasm_runtime_lookup_function(instance->instance, name.c_str());
231242
if (!func)
232243
{

0 commit comments

Comments
 (0)