Преглед изворни кода

fix: 修复派生env的status_lock未初始化问题

SongZihuan пре 3 година
родитељ
комит
6629c92eae
2 измењених фајлова са 9 додато и 7 уклоњено
  1. 5 3
      src/core/env.c
  2. 4 4
      src/core/run.c

+ 5 - 3
src/core/env.c

@@ -941,6 +941,9 @@ af_Environment *deriveEnvironment(bool derive_tmp, bool derive_guardian, bool de
     pthread_mutex_init(&env->in_run, &attr);  // 检测锁
     pthread_mutex_init(&env->in_run, &attr);  // 检测锁
     pthread_mutexattr_destroy(&attr);
     pthread_mutexattr_destroy(&attr);
 
 
+    pthread_mutex_init(&env->thread_lock, NULL);
+    pthread_mutex_init(&env->status_lock, NULL);
+
     env->is_derive = true;
     env->is_derive = true;
     env->base = base->base;
     env->base = base->base;
     pushEnvironmentList(env, base);
     pushEnvironmentList(env, base);
@@ -990,7 +993,6 @@ af_Environment *deriveEnvironment(bool derive_tmp, bool derive_guardian, bool de
         env->status = core_init;
         env->status = core_init;
 
 
     env->activity = makeTopActivity(NULL, NULL, env->protect, env->global);
     env->activity = makeTopActivity(NULL, NULL, env->protect, env->global);
-    pthread_mutex_init(&env->thread_lock, NULL);
     return env;
     return env;
 }
 }
 
 
@@ -1777,10 +1779,10 @@ bool freeEnvironmentListByEnv(af_Environment *env, af_Environment *base) {
 
 
 void pushEnvironmentList(af_Environment *env, af_Environment *base) {
 void pushEnvironmentList(af_Environment *env, af_Environment *base) {
     af_EnvironmentList *envl = makeEnvironmentList(env);
     af_EnvironmentList *envl = makeEnvironmentList(env);
-    pthread_mutex_lock(&env->thread_lock);
+    pthread_mutex_lock(&base->thread_lock);
     envl->next = base->env_list;
     envl->next = base->env_list;
     base->env_list = envl;
     base->env_list = envl;
-    pthread_mutex_unlock(&env->thread_lock);
+    pthread_mutex_unlock(&base->thread_lock);
 }
 }
 
 
 af_ErrorInfo *makeErrorInfo(char *type, char *error, char *note, FileLine line, FilePath path) {
 af_ErrorInfo *makeErrorInfo(char *type, char *error, char *note, FileLine line, FilePath path) {

+ 4 - 4
src/core/run.c

@@ -107,10 +107,6 @@ static bool iterCodeInit(af_Code *code, int mode, af_Environment *env) {
         return false;
         return false;
     }
     }
 
 
-    pthread_mutex_lock(&env->status_lock);
-    env->status = core_normal_gc;
-    pthread_mutex_unlock(&env->status_lock);
-
     switch (mode) {
     switch (mode) {
         case 0:
         case 0:
             if (env->activity->type != act_top || !codeSemanticCheck(code))
             if (env->activity->type != act_top || !codeSemanticCheck(code))
@@ -137,6 +133,10 @@ static bool iterCodeInit(af_Code *code, int mode, af_Environment *env) {
                 return false;
                 return false;
             break;
             break;
         case 3:
         case 3:
+            pthread_mutex_lock(&env->status_lock);
+            env->status = core_normal_gc;
+            pthread_mutex_unlock(&env->status_lock);
+
             if (env->activity->type != act_guardian || code != NULL)
             if (env->activity->type != act_guardian || code != NULL)
                 return false;
                 return false;
             break;
             break;