Spread module custom data to all threads, enable libc-builtin float print (#633)
This commit is contained in:
@ -535,13 +535,13 @@ pthread_create_wrapper(wasm_exec_env_t exec_env,
|
||||
void *arg) /* arguments buffer */
|
||||
{
|
||||
wasm_module_t module = get_module(exec_env);
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
wasm_module_inst_t new_module_inst = NULL;
|
||||
ThreadInfoNode *info_node = NULL;
|
||||
ThreadRoutineArgs *routine_args = NULL;
|
||||
uint32 thread_handle;
|
||||
int32 ret = -1;
|
||||
#if WASM_ENABLE_LIBC_WASI != 0
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
WASIContext *wasi_ctx = get_wasi_ctx(module_inst);
|
||||
#endif
|
||||
|
||||
@ -552,6 +552,13 @@ pthread_create_wrapper(wasm_exec_env_t exec_env,
|
||||
NULL, 0)))
|
||||
return -1;
|
||||
|
||||
if (module_inst) {
|
||||
/* Set custom_data to new module instance */
|
||||
wasm_runtime_set_custom_data_internal(
|
||||
new_module_inst,
|
||||
wasm_runtime_get_custom_data(module_inst));
|
||||
}
|
||||
|
||||
#if WASM_ENABLE_LIBC_WASI != 0
|
||||
if (wasi_ctx)
|
||||
wasm_runtime_set_wasi_ctx(new_module_inst, wasi_ctx);
|
||||
|
||||
@ -361,6 +361,19 @@ handle_1_to_9:
|
||||
break;
|
||||
}
|
||||
|
||||
case 'f': {
|
||||
float64 f64;
|
||||
char buf[16], *s;
|
||||
|
||||
CHECK_VA_ARG(ap, float64);
|
||||
f64 = _va_arg(ap, float64);
|
||||
snprintf(buf, sizeof(buf), "%f", f64);
|
||||
s = buf;
|
||||
while (*s)
|
||||
out((int) (*s++), ctx);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
out((int) '%', ctx);
|
||||
out((int) *fmt, ctx);
|
||||
|
||||
@ -328,6 +328,7 @@ WASMExecEnv *
|
||||
wasm_cluster_spawn_exec_env(WASMExecEnv *exec_env)
|
||||
{
|
||||
WASMCluster *cluster = wasm_exec_env_get_cluster(exec_env);
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
wasm_module_t module = wasm_exec_env_get_module(exec_env);
|
||||
wasm_module_inst_t new_module_inst;
|
||||
WASMExecEnv *new_exec_env;
|
||||
@ -343,6 +344,13 @@ wasm_cluster_spawn_exec_env(WASMExecEnv *exec_env)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (module_inst) {
|
||||
/* Set custom_data to new module instance */
|
||||
wasm_runtime_set_custom_data_internal(
|
||||
new_module_inst,
|
||||
wasm_runtime_get_custom_data(module_inst));
|
||||
}
|
||||
|
||||
new_exec_env = wasm_exec_env_create_internal(
|
||||
new_module_inst, exec_env->wasm_stack_size);
|
||||
if (!new_exec_env)
|
||||
@ -654,3 +662,24 @@ wasm_cluster_spread_exception(WASMExecEnv *exec_env)
|
||||
|
||||
traverse_list(&cluster->exec_env_list, set_exception_visitor, exec_env);
|
||||
}
|
||||
|
||||
static void
|
||||
set_custom_data_visitor(void *node, void *user_data)
|
||||
{
|
||||
WASMExecEnv *curr_exec_env = (WASMExecEnv *)node;
|
||||
WASMModuleInstanceCommon *module_inst = get_module_inst(curr_exec_env);
|
||||
|
||||
wasm_runtime_set_custom_data_internal(module_inst, user_data);
|
||||
}
|
||||
|
||||
void
|
||||
wasm_cluster_spread_custom_data(WASMModuleInstanceCommon *module_inst,
|
||||
void *custom_data)
|
||||
{
|
||||
WASMExecEnv *exec_env = wasm_clusters_search_exec_env(module_inst);
|
||||
WASMCluster *cluster = wasm_exec_env_get_cluster(exec_env);
|
||||
|
||||
traverse_list(&cluster->exec_env_list,
|
||||
set_custom_data_visitor,
|
||||
custom_data);
|
||||
}
|
||||
|
||||
@ -118,6 +118,10 @@ wasm_cluster_spawn_exec_env(WASMExecEnv *exec_env);
|
||||
void
|
||||
wasm_cluster_destroy_spawned_exec_env(WASMExecEnv *exec_env);
|
||||
|
||||
void
|
||||
wasm_cluster_spread_custom_data(WASMModuleInstanceCommon *module_inst,
|
||||
void *custom_data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user