Browse Source

Core: Protect each event from race conditions within it.

Fernando Sahmkow 4 năm trước cách đây
mục cha
commit
38e4a144a1
2 tập tin đã thay đổi với 2 bổ sung0 xóa
  1. 1 0
      src/core/core_timing.cpp
  2. 1 0
      src/core/core_timing.h

+ 1 - 0
src/core/core_timing.cpp

@@ -226,6 +226,7 @@ std::optional<s64> CoreTiming::Advance() {
         event_mutex.unlock();
 
         if (const auto event_type{evt.type.lock()}) {
+            std::unique_lock<std::mutex> lk(event_type->guard);
             event_type->callback(evt.user_data, std::chrono::nanoseconds{static_cast<s64>(
                                                     GetGlobalTimeNs().count() - evt.time)});
         }

+ 1 - 0
src/core/core_timing.h

@@ -32,6 +32,7 @@ struct EventType {
     TimedCallback callback;
     /// A pointer to the name of the event.
     const std::string name;
+    mutable std::mutex guard;
 };
 
 /**