Kaynağa Gözat

Don't call os_thread_get_stack_boundary unless we actually use it (#4264)

Previously, if the user sets their own stack boundary, we still compute
the thread stack boundary (which is expensive), then immediately discard
the result. This change makes the expensive call only if we need it for
sure.
James Ring 10 ay önce
ebeveyn
işleme
c48dd5ccd7
1 değiştirilmiş dosya ile 3 ekleme ve 3 silme
  1. 3 3
      core/iwasm/common/wasm_exec_env.c

+ 3 - 3
core/iwasm/common/wasm_exec_env.c

@@ -276,8 +276,6 @@ wasm_exec_env_restore_module_inst(
 void
 void
 wasm_exec_env_set_thread_info(WASMExecEnv *exec_env)
 wasm_exec_env_set_thread_info(WASMExecEnv *exec_env)
 {
 {
-    uint8 *stack_boundary = os_thread_get_stack_boundary();
-
 #if WASM_ENABLE_THREAD_MGR != 0
 #if WASM_ENABLE_THREAD_MGR != 0
     os_mutex_lock(&exec_env->wait_lock);
     os_mutex_lock(&exec_env->wait_lock);
 #endif
 #endif
@@ -286,9 +284,11 @@ wasm_exec_env_set_thread_info(WASMExecEnv *exec_env)
         /* WASM_STACK_GUARD_SIZE isn't added for flexibility to developer,
         /* WASM_STACK_GUARD_SIZE isn't added for flexibility to developer,
            he must ensure that enough guard bytes are kept. */
            he must ensure that enough guard bytes are kept. */
         exec_env->native_stack_boundary = exec_env->user_native_stack_boundary;
         exec_env->native_stack_boundary = exec_env->user_native_stack_boundary;
-    else
+    else {
+        uint8 *stack_boundary = os_thread_get_stack_boundary();
         exec_env->native_stack_boundary =
         exec_env->native_stack_boundary =
             stack_boundary ? stack_boundary + WASM_STACK_GUARD_SIZE : NULL;
             stack_boundary ? stack_boundary + WASM_STACK_GUARD_SIZE : NULL;
+    }
     exec_env->native_stack_top_min = (void *)UINTPTR_MAX;
     exec_env->native_stack_top_min = (void *)UINTPTR_MAX;
 #if WASM_ENABLE_THREAD_MGR != 0
 #if WASM_ENABLE_THREAD_MGR != 0
     os_mutex_unlock(&exec_env->wait_lock);
     os_mutex_unlock(&exec_env->wait_lock);