From 0f8e5a146563d1f245f8f62cb931dc1e0b55de2f Mon Sep 17 00:00:00 2001 From: Fernando Sahmkow Date: Sat, 8 Feb 2020 12:48:57 -0400 Subject: Tests: Add base tests to host timing --- src/core/host_timing.h | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'src/core/host_timing.h') diff --git a/src/core/host_timing.h b/src/core/host_timing.h index a3a32e087..1d053a7fa 100644 --- a/src/core/host_timing.h +++ b/src/core/host_timing.h @@ -14,13 +14,15 @@ #include #include "common/common_types.h" +#include "common/spin_lock.h" +#include "common/thread.h" #include "common/threadsafe_queue.h" namespace Core::HostTiming { /// A callback that may be scheduled for a particular core timing event. using TimedCallback = std::function; -using sys_time_point = std::chrono::time_point; +using sys_time_point = std::chrono::time_point; /// Contains the characteristics of a particular event. struct EventType { @@ -63,6 +65,23 @@ public: /// Tears down all timing related functionality. void Shutdown(); + /// Pauses/Unpauses the execution of the timer thread. + void Pause(bool is_paused); + + /// Pauses/Unpauses the execution of the timer thread and waits until paused. + void SyncPause(bool is_paused); + + /// Checks if core timing is running. + bool IsRunning(); + + /// Checks if the timer thread has started. + bool HasStarted() { + return has_started; + } + + /// Checks if there are any pending time events. + bool HasPendingEvents(); + /// Schedules an event in core timing void ScheduleEvent(s64 ns_into_future, const std::shared_ptr& event_type, u64 userdata = 0); @@ -107,11 +126,14 @@ private: u64 event_fifo_id = 0; std::shared_ptr ev_lost; - bool is_set = false; - std::condition_variable condvar; - std::mutex inner_mutex; + Common::Event event{}; + Common::SpinLock basic_lock{}; std::unique_ptr timer_thread; + std::atomic paused{}; + std::atomic paused_set{}; + std::atomic wait_set{}; std::atomic shutting_down{}; + std::atomic has_started{}; }; /// Creates a core timing event with the given name and callback. -- cgit v1.2.3