|
|
@@ -208,6 +208,33 @@ free_aux_stack(WASMExecEnv *exec_env, uint32 start)
|
|
|
#endif
|
|
|
}
|
|
|
|
|
|
+bool
|
|
|
+wasm_cluster_allocate_aux_stack(WASMExecEnv *exec_env, uint32 *p_start,
|
|
|
+ uint32 *p_size)
|
|
|
+{
|
|
|
+ WASMCluster *cluster = wasm_exec_env_get_cluster(exec_env);
|
|
|
+ bool ret;
|
|
|
+
|
|
|
+ os_mutex_lock(&cluster->lock);
|
|
|
+ ret = allocate_aux_stack(exec_env, p_start, p_size);
|
|
|
+ os_mutex_unlock(&cluster->lock);
|
|
|
+
|
|
|
+ return ret;
|
|
|
+}
|
|
|
+
|
|
|
+bool
|
|
|
+wasm_cluster_free_aux_stack(WASMExecEnv *exec_env, uint32 start)
|
|
|
+{
|
|
|
+ WASMCluster *cluster = wasm_exec_env_get_cluster(exec_env);
|
|
|
+ bool ret;
|
|
|
+
|
|
|
+ os_mutex_lock(&cluster->lock);
|
|
|
+ ret = free_aux_stack(exec_env, start);
|
|
|
+ os_mutex_unlock(&cluster->lock);
|
|
|
+
|
|
|
+ return ret;
|
|
|
+}
|
|
|
+
|
|
|
WASMCluster *
|
|
|
wasm_cluster_create(WASMExecEnv *exec_env)
|
|
|
{
|
|
|
@@ -654,12 +681,13 @@ thread_manager_start_routine(void *arg)
|
|
|
|
|
|
int32
|
|
|
wasm_cluster_create_thread(WASMExecEnv *exec_env,
|
|
|
- wasm_module_inst_t module_inst, bool alloc_aux_stack,
|
|
|
+ wasm_module_inst_t module_inst,
|
|
|
+ bool is_aux_stack_allocated, uint32 aux_stack_start,
|
|
|
+ uint32 aux_stack_size,
|
|
|
void *(*thread_routine)(void *), void *arg)
|
|
|
{
|
|
|
WASMCluster *cluster;
|
|
|
WASMExecEnv *new_exec_env;
|
|
|
- uint32 aux_stack_start = 0, aux_stack_size;
|
|
|
korp_tid tid;
|
|
|
|
|
|
cluster = wasm_exec_env_get_cluster(exec_env);
|
|
|
@@ -676,17 +704,11 @@ wasm_cluster_create_thread(WASMExecEnv *exec_env,
|
|
|
if (!new_exec_env)
|
|
|
goto fail1;
|
|
|
|
|
|
- if (alloc_aux_stack) {
|
|
|
- if (!allocate_aux_stack(exec_env, &aux_stack_start, &aux_stack_size)) {
|
|
|
- LOG_ERROR("thread manager error: "
|
|
|
- "failed to allocate aux stack space for new thread");
|
|
|
- goto fail2;
|
|
|
- }
|
|
|
-
|
|
|
+ if (is_aux_stack_allocated) {
|
|
|
/* Set aux stack for current thread */
|
|
|
if (!wasm_exec_env_set_aux_stack(new_exec_env, aux_stack_start,
|
|
|
aux_stack_size)) {
|
|
|
- goto fail3;
|
|
|
+ goto fail2;
|
|
|
}
|
|
|
}
|
|
|
else {
|
|
|
@@ -699,7 +721,7 @@ wasm_cluster_create_thread(WASMExecEnv *exec_env,
|
|
|
new_exec_env->suspend_flags.flags = exec_env->suspend_flags.flags;
|
|
|
|
|
|
if (!wasm_cluster_add_exec_env(cluster, new_exec_env))
|
|
|
- goto fail3;
|
|
|
+ goto fail2;
|
|
|
|
|
|
new_exec_env->thread_start_routine = thread_routine;
|
|
|
new_exec_env->thread_arg = arg;
|
|
|
@@ -711,7 +733,7 @@ wasm_cluster_create_thread(WASMExecEnv *exec_env,
|
|
|
(void *)new_exec_env,
|
|
|
APP_THREAD_STACK_SIZE_DEFAULT)) {
|
|
|
os_mutex_unlock(&new_exec_env->wait_lock);
|
|
|
- goto fail4;
|
|
|
+ goto fail3;
|
|
|
}
|
|
|
|
|
|
/* Wait until the new_exec_env->handle is set to avoid it is
|
|
|
@@ -723,12 +745,8 @@ wasm_cluster_create_thread(WASMExecEnv *exec_env,
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
-fail4:
|
|
|
- wasm_cluster_del_exec_env_internal(cluster, new_exec_env, false);
|
|
|
fail3:
|
|
|
- /* free the allocated aux stack space */
|
|
|
- if (alloc_aux_stack)
|
|
|
- free_aux_stack(exec_env, aux_stack_start);
|
|
|
+ wasm_cluster_del_exec_env_internal(cluster, new_exec_env, false);
|
|
|
fail2:
|
|
|
wasm_exec_env_destroy_internal(new_exec_env);
|
|
|
fail1:
|