summaryrefslogtreecommitdiff
path: root/src/core/core_timing.h
diff options
context:
space:
mode:
authorGravatar Kelebek12022-07-10 06:59:40 +0100
committerGravatar Kelebek12022-07-10 06:59:40 +0100
commit240650f6a6336df8d3eb11b410cdcd332d8ad562 (patch)
tree16ae249e6160a22f88bd2238d43b23079c4afb44 /src/core/core_timing.h
parentMerge pull request #8531 from FernandoS27/core-timing-fix-reg (diff)
downloadyuzu-240650f6a6336df8d3eb11b410cdcd332d8ad562.tar.gz
yuzu-240650f6a6336df8d3eb11b410cdcd332d8ad562.tar.xz
yuzu-240650f6a6336df8d3eb11b410cdcd332d8ad562.zip
Rework CoreTiming
Diffstat (limited to 'src/core/core_timing.h')
-rw-r--r--src/core/core_timing.h23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/core/core_timing.h b/src/core/core_timing.h
index c52bffb3b..09b6ed81a 100644
--- a/src/core/core_timing.h
+++ b/src/core/core_timing.h
@@ -20,8 +20,9 @@
20namespace Core::Timing { 20namespace Core::Timing {
21 21
22/// A callback that may be scheduled for a particular core timing event. 22/// A callback that may be scheduled for a particular core timing event.
23using TimedCallback = 23using TimedCallback = std::function<std::optional<std::chrono::nanoseconds>(
24 std::function<void(std::uintptr_t user_data, std::chrono::nanoseconds ns_late)>; 24 std::uintptr_t user_data, s64 time, std::chrono::nanoseconds ns_late)>;
25using PauseCallback = std::function<void(bool paused)>;
25 26
26/// Contains the characteristics of a particular event. 27/// Contains the characteristics of a particular event.
27struct EventType { 28struct EventType {
@@ -93,7 +94,15 @@ public:
93 94
94 /// Schedules an event in core timing 95 /// Schedules an event in core timing
95 void ScheduleEvent(std::chrono::nanoseconds ns_into_future, 96 void ScheduleEvent(std::chrono::nanoseconds ns_into_future,
96 const std::shared_ptr<EventType>& event_type, std::uintptr_t user_data = 0); 97 const std::shared_ptr<EventType>& event_type, std::uintptr_t user_data = 0,
98 bool absolute_time = false);
99
100 /// Schedules an event which will automatically re-schedule itself with the given time, until
101 /// unscheduled
102 void ScheduleLoopingEvent(std::chrono::nanoseconds start_time,
103 std::chrono::nanoseconds resched_time,
104 const std::shared_ptr<EventType>& event_type,
105 std::uintptr_t user_data = 0, bool absolute_time = false);
97 106
98 void UnscheduleEvent(const std::shared_ptr<EventType>& event_type, std::uintptr_t user_data); 107 void UnscheduleEvent(const std::shared_ptr<EventType>& event_type, std::uintptr_t user_data);
99 108
@@ -125,6 +134,9 @@ public:
125 /// Checks for events manually and returns time in nanoseconds for next event, threadsafe. 134 /// Checks for events manually and returns time in nanoseconds for next event, threadsafe.
126 std::optional<s64> Advance(); 135 std::optional<s64> Advance();
127 136
137 /// Register a callback function to be called when coretiming pauses.
138 void RegisterPauseCallback(PauseCallback&& callback);
139
128private: 140private:
129 struct Event; 141 struct Event;
130 142
@@ -136,7 +148,7 @@ private:
136 148
137 std::unique_ptr<Common::WallClock> clock; 149 std::unique_ptr<Common::WallClock> clock;
138 150
139 u64 global_timer = 0; 151 s64 global_timer = 0;
140 152
141 // The queue is a min-heap using std::make_heap/push_heap/pop_heap. 153 // The queue is a min-heap using std::make_heap/push_heap/pop_heap.
142 // We don't use std::priority_queue because we need to be able to serialize, unserialize and 154 // We don't use std::priority_queue because we need to be able to serialize, unserialize and
@@ -162,10 +174,13 @@ private:
162 bool shutting_down{}; 174 bool shutting_down{};
163 bool is_multicore{}; 175 bool is_multicore{};
164 size_t pause_count{}; 176 size_t pause_count{};
177 s64 pause_end_time{};
165 178
166 /// Cycle timing 179 /// Cycle timing
167 u64 ticks{}; 180 u64 ticks{};
168 s64 downcount{}; 181 s64 downcount{};
182
183 std::vector<PauseCallback> pause_callbacks{};
169}; 184};
170 185
171/// Creates a core timing event with the given name and callback. 186/// Creates a core timing event with the given name and callback.