From eb6a9c8efb21beb07dea132d9ef369d466c0c308 Mon Sep 17 00:00:00 2001 From: pineappleEA Date: Thu, 30 Jun 2022 13:30:20 +0200 Subject: [PATCH] early-access version 2808 --- README.md | 2 +- src/core/core_timing.cpp | 21 +++++++++++++++------ src/core/core_timing.h | 2 ++ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 9b074b6b3..f8541515e 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ yuzu emulator early access ============= -This is the source code for early-access 2807. +This is the source code for early-access 2808. ## Legal Notice diff --git a/src/core/core_timing.cpp b/src/core/core_timing.cpp index 0db6cfb70..140578069 100755 --- a/src/core/core_timing.cpp +++ b/src/core/core_timing.cpp @@ -6,6 +6,7 @@ #include #include +#include "common/logging/log.h" #include "common/microprofile.h" #include "common/thread.h" #include "core/core_timing.h" @@ -128,7 +129,7 @@ bool CoreTiming::IsRunning() const { bool CoreTiming::HasPendingEvents() const { std::unique_lock main_lock(event_mutex); - return !event_queue.empty(); + return !event_queue.empty() || pending_events.load(std::memory_order_relaxed) != 0; } void CoreTiming::ScheduleEvent(std::chrono::nanoseconds ns_into_future, @@ -139,6 +140,7 @@ void CoreTiming::ScheduleEvent(std::chrono::nanoseconds ns_into_future, const u64 timeout = static_cast((GetGlobalTimeNs() + ns_into_future).count()); event_queue.emplace_back(Event{timeout, event_fifo_id++, user_data, event_type}); + pending_events.fetch_add(1, std::memory_order_relaxed); std::push_heap(event_queue.begin(), event_queue.end(), std::greater<>()); @@ -158,6 +160,7 @@ void CoreTiming::UnscheduleEvent(const std::shared_ptr& event_type, if (itr != event_queue.end()) { event_queue.erase(itr, event_queue.end()); std::make_heap(event_queue.begin(), event_queue.end(), std::greater<>()); + pending_events.fetch_sub(1, std::memory_order_relaxed); } } @@ -223,15 +226,21 @@ std::optional CoreTiming::Advance() { Event evt = std::move(event_queue.front()); std::pop_heap(event_queue.begin(), event_queue.end(), std::greater<>()); event_queue.pop_back(); - 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)}); + sequence_mutex.lock(); + event_mutex.unlock(); + + event_type->guard.lock(); + sequence_mutex.unlock(); + const s64 delay = static_cast(GetGlobalTimeNs().count() - evt.time); + event_type->callback(evt.user_data, std::chrono::nanoseconds{delay}); + event_type->guard.unlock(); + + event_mutex.lock(); + pending_events.fetch_sub(1, std::memory_order_relaxed); } - event_mutex.lock(); global_timer = GetGlobalTimeNs().count(); } diff --git a/src/core/core_timing.h b/src/core/core_timing.h index b65cbb13d..a86553e08 100755 --- a/src/core/core_timing.h +++ b/src/core/core_timing.h @@ -145,6 +145,7 @@ private: // accomodated by the standard adaptor class. std::vector event_queue; u64 event_fifo_id = 0; + std::atomic pending_events{}; std::shared_ptr ev_lost; std::atomic has_started{}; @@ -156,6 +157,7 @@ private: std::condition_variable wait_pause_cv; std::condition_variable wait_signal_cv; mutable std::mutex event_mutex; + mutable std::mutex sequence_mutex; std::atomic paused_state{}; bool is_paused{};