From 38e4a144a1e6f399482eb586c1e0d5646fae9679 Mon Sep 17 00:00:00 2001 From: Fernando Sahmkow Date: Sun, 28 Nov 2021 13:47:40 +0100 Subject: Core: Protect each event from race conditions within it. --- src/core/core_timing.cpp | 1 + src/core/core_timing.h | 1 + 2 files changed, 2 insertions(+) (limited to 'src') diff --git a/src/core/core_timing.cpp b/src/core/core_timing.cpp index b6c295ada..18dfa07f5 100644 --- a/src/core/core_timing.cpp +++ b/src/core/core_timing.cpp @@ -226,6 +226,7 @@ std::optional CoreTiming::Advance() { event_mutex.unlock(); if (const auto event_type{evt.type.lock()}) { + std::unique_lock lk(event_type->guard); event_type->callback(evt.user_data, std::chrono::nanoseconds{static_cast( GetGlobalTimeNs().count() - evt.time)}); } diff --git a/src/core/core_timing.h b/src/core/core_timing.h index 901bf532e..4fef6fcce 100644 --- a/src/core/core_timing.h +++ b/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; }; /** -- cgit v1.2.3