From 07993ac8c8c66bbf638dddc7750106f6dfb0e09b Mon Sep 17 00:00:00 2001 From: Fernando Sahmkow Date: Tue, 3 Mar 2020 15:50:38 -0400 Subject: Kernel: Corrections to Scheduling. --- src/core/core_timing.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/core/core_timing.cpp') diff --git a/src/core/core_timing.cpp b/src/core/core_timing.cpp index 5a7abcfca..c91ae9975 100644 --- a/src/core/core_timing.cpp +++ b/src/core/core_timing.cpp @@ -154,7 +154,7 @@ void CoreTiming::RemoveEvent(const std::shared_ptr& event_type) { basic_lock.unlock(); } -std::optional CoreTiming::Advance() { +std::optional CoreTiming::Advance() { advance_lock.lock(); basic_lock.lock(); global_timer = GetGlobalTimeNs().count(); @@ -170,10 +170,11 @@ std::optional CoreTiming::Advance() { } basic_lock.lock(); + global_timer = GetGlobalTimeNs().count(); } if (!event_queue.empty()) { - const u64 next_time = event_queue.front().time - global_timer; + const s64 next_time = event_queue.front().time - global_timer; basic_lock.unlock(); advance_lock.unlock(); return next_time; @@ -191,8 +192,10 @@ void CoreTiming::ThreadLoop() { paused_set = false; const auto next_time = Advance(); if (next_time) { - std::chrono::nanoseconds next_time_ns = std::chrono::nanoseconds(*next_time); - event.WaitFor(next_time_ns); + if (*next_time > 0) { + std::chrono::nanoseconds next_time_ns = std::chrono::nanoseconds(*next_time); + event.WaitFor(next_time_ns); + } } else { wait_set = true; event.Wait(); -- cgit v1.2.3