summaryrefslogtreecommitdiff
path: root/src/core/core_timing.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/core_timing.h')
-rw-r--r--src/core/core_timing.h27
1 files changed, 14 insertions, 13 deletions
diff --git a/src/core/core_timing.h b/src/core/core_timing.h
index 21548f0a9..7e4dff7f3 100644
--- a/src/core/core_timing.h
+++ b/src/core/core_timing.h
@@ -22,17 +22,25 @@ namespace Core::Timing {
22 22
23/// 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.
24using TimedCallback = std::function<std::optional<std::chrono::nanoseconds>( 24using TimedCallback = std::function<std::optional<std::chrono::nanoseconds>(
25 std::uintptr_t user_data, s64 time, std::chrono::nanoseconds ns_late)>; 25 s64 time, std::chrono::nanoseconds ns_late)>;
26 26
27/// Contains the characteristics of a particular event. 27/// Contains the characteristics of a particular event.
28struct EventType { 28struct EventType {
29 explicit EventType(TimedCallback&& callback_, std::string&& name_) 29 explicit EventType(TimedCallback&& callback_, std::string&& name_)
30 : callback{std::move(callback_)}, name{std::move(name_)} {} 30 : callback{std::move(callback_)}, name{std::move(name_)}, sequence_number{0} {}
31 31
32 /// The event's callback function. 32 /// The event's callback function.
33 TimedCallback callback; 33 TimedCallback callback;
34 /// A pointer to the name of the event. 34 /// A pointer to the name of the event.
35 const std::string name; 35 const std::string name;
36 /// A monotonic sequence number, incremented when this event is
37 /// changed externally.
38 size_t sequence_number;
39};
40
41enum class UnscheduleEventType {
42 Wait,
43 NoWait,
36}; 44};
37 45
38/** 46/**
@@ -89,23 +97,17 @@ public:
89 97
90 /// Schedules an event in core timing 98 /// Schedules an event in core timing
91 void ScheduleEvent(std::chrono::nanoseconds ns_into_future, 99 void ScheduleEvent(std::chrono::nanoseconds ns_into_future,
92 const std::shared_ptr<EventType>& event_type, std::uintptr_t user_data = 0, 100 const std::shared_ptr<EventType>& event_type, bool absolute_time = false);
93 bool absolute_time = false);
94 101
95 /// Schedules an event which will automatically re-schedule itself with the given time, until 102 /// Schedules an event which will automatically re-schedule itself with the given time, until
96 /// unscheduled 103 /// unscheduled
97 void ScheduleLoopingEvent(std::chrono::nanoseconds start_time, 104 void ScheduleLoopingEvent(std::chrono::nanoseconds start_time,
98 std::chrono::nanoseconds resched_time, 105 std::chrono::nanoseconds resched_time,
99 const std::shared_ptr<EventType>& event_type, 106 const std::shared_ptr<EventType>& event_type,
100 std::uintptr_t user_data = 0, bool absolute_time = false); 107 bool absolute_time = false);
101 108
102 void UnscheduleEvent(const std::shared_ptr<EventType>& event_type, std::uintptr_t user_data, 109 void UnscheduleEvent(const std::shared_ptr<EventType>& event_type,
103 bool wait = true); 110 UnscheduleEventType type = UnscheduleEventType::Wait);
104
105 void UnscheduleEventWithoutWait(const std::shared_ptr<EventType>& event_type,
106 std::uintptr_t user_data) {
107 UnscheduleEvent(event_type, user_data, false);
108 }
109 111
110 void AddTicks(u64 ticks_to_add); 112 void AddTicks(u64 ticks_to_add);
111 113
@@ -158,7 +160,6 @@ private:
158 heap_t event_queue; 160 heap_t event_queue;
159 u64 event_fifo_id = 0; 161 u64 event_fifo_id = 0;
160 162
161 std::shared_ptr<EventType> ev_lost;
162 Common::Event event{}; 163 Common::Event event{};
163 Common::Event pause_event{}; 164 Common::Event pause_event{};
164 mutable std::mutex basic_lock; 165 mutable std::mutex basic_lock;