summaryrefslogtreecommitdiff
path: root/src/core/host_timing.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/host_timing.h')
-rw-r--r--src/core/host_timing.h30
1 files changed, 26 insertions, 4 deletions
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 @@
14#include <vector> 14#include <vector>
15 15
16#include "common/common_types.h" 16#include "common/common_types.h"
17#include "common/spin_lock.h"
18#include "common/thread.h"
17#include "common/threadsafe_queue.h" 19#include "common/threadsafe_queue.h"
18 20
19namespace Core::HostTiming { 21namespace Core::HostTiming {
20 22
21/// A callback that may be scheduled for a particular core timing event. 23/// A callback that may be scheduled for a particular core timing event.
22using TimedCallback = std::function<void(u64 userdata, s64 cycles_late)>; 24using TimedCallback = std::function<void(u64 userdata, s64 cycles_late)>;
23using sys_time_point = std::chrono::time_point<std::chrono::system_clock>; 25using sys_time_point = std::chrono::time_point<std::chrono::steady_clock>;
24 26
25/// Contains the characteristics of a particular event. 27/// Contains the characteristics of a particular event.
26struct EventType { 28struct EventType {
@@ -63,6 +65,23 @@ public:
63 /// Tears down all timing related functionality. 65 /// Tears down all timing related functionality.
64 void Shutdown(); 66 void Shutdown();
65 67
68 /// Pauses/Unpauses the execution of the timer thread.
69 void Pause(bool is_paused);
70
71 /// Pauses/Unpauses the execution of the timer thread and waits until paused.
72 void SyncPause(bool is_paused);
73
74 /// Checks if core timing is running.
75 bool IsRunning();
76
77 /// Checks if the timer thread has started.
78 bool HasStarted() {
79 return has_started;
80 }
81
82 /// Checks if there are any pending time events.
83 bool HasPendingEvents();
84
66 /// Schedules an event in core timing 85 /// Schedules an event in core timing
67 void ScheduleEvent(s64 ns_into_future, const std::shared_ptr<EventType>& event_type, 86 void ScheduleEvent(s64 ns_into_future, const std::shared_ptr<EventType>& event_type,
68 u64 userdata = 0); 87 u64 userdata = 0);
@@ -107,11 +126,14 @@ private:
107 u64 event_fifo_id = 0; 126 u64 event_fifo_id = 0;
108 127
109 std::shared_ptr<EventType> ev_lost; 128 std::shared_ptr<EventType> ev_lost;
110 bool is_set = false; 129 Common::Event event{};
111 std::condition_variable condvar; 130 Common::SpinLock basic_lock{};
112 std::mutex inner_mutex;
113 std::unique_ptr<std::thread> timer_thread; 131 std::unique_ptr<std::thread> timer_thread;
132 std::atomic<bool> paused{};
133 std::atomic<bool> paused_set{};
134 std::atomic<bool> wait_set{};
114 std::atomic<bool> shutting_down{}; 135 std::atomic<bool> shutting_down{};
136 std::atomic<bool> has_started{};
115}; 137};
116 138
117/// Creates a core timing event with the given name and callback. 139/// Creates a core timing event with the given name and callback.