Browse Source

Fixed some log related thread-safety warnings

Sam Lantinga 21 giờ trước cách đây
mục cha
commit
90756b542f
1 tập tin đã thay đổi với 12 bổ sung0 xóa
  1. 12 0
      src/SDL_log.c

+ 12 - 0
src/SDL_log.c

@@ -180,11 +180,15 @@ static void SDL_CheckInitLog(void)
 
 
 static void CleanupLogPriorities(void)
 static void CleanupLogPriorities(void)
 {
 {
+    SDL_LockMutex(SDL_log_lock);
+
     while (SDL_loglevels) {
     while (SDL_loglevels) {
         SDL_LogLevel *entry = SDL_loglevels;
         SDL_LogLevel *entry = SDL_loglevels;
         SDL_loglevels = entry->next;
         SDL_loglevels = entry->next;
         SDL_free(entry);
         SDL_free(entry);
     }
     }
+
+    SDL_UnlockMutex(SDL_log_lock);
 }
 }
 
 
 void SDL_SetLogPriorities(SDL_LogPriority priority)
 void SDL_SetLogPriorities(SDL_LogPriority priority)
@@ -339,6 +343,8 @@ static void ParseLogPriorities(const char *hint)
         return;
         return;
     }
     }
 
 
+    SDL_LockMutex(SDL_log_lock);
+
     for (name = hint; name; name = next) {
     for (name = hint; name; name = next) {
         const char *sep = SDL_strchr(name, '=');
         const char *sep = SDL_strchr(name, '=');
         if (!sep) {
         if (!sep) {
@@ -371,6 +377,8 @@ static void ParseLogPriorities(const char *hint)
             }
             }
         }
         }
     }
     }
+
+    SDL_UnlockMutex(SDL_log_lock);
 }
 }
 
 
 void SDL_ResetLogPriorities(void)
 void SDL_ResetLogPriorities(void)
@@ -431,12 +439,16 @@ void SDL_ResetLogPriorities(void)
 
 
 static void CleanupLogPrefixes(void)
 static void CleanupLogPrefixes(void)
 {
 {
+    SDL_LockMutex(SDL_log_function_lock);
+
     for (int i = 0; i < SDL_arraysize(SDL_priority_prefixes); ++i) {
     for (int i = 0; i < SDL_arraysize(SDL_priority_prefixes); ++i) {
         if (SDL_priority_prefixes[i]) {
         if (SDL_priority_prefixes[i]) {
             SDL_free(SDL_priority_prefixes[i]);
             SDL_free(SDL_priority_prefixes[i]);
             SDL_priority_prefixes[i] = NULL;
             SDL_priority_prefixes[i] = NULL;
         }
         }
     }
     }
+
+    SDL_UnlockMutex(SDL_log_function_lock);
 }
 }
 
 
 static const char *GetLogPriorityPrefix(SDL_LogPriority priority)
 static const char *GetLogPriorityPrefix(SDL_LogPriority priority)