summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/core_timing.cpp14
-rw-r--r--src/core/core_timing.h5
2 files changed, 15 insertions, 4 deletions
diff --git a/src/core/core_timing.cpp b/src/core/core_timing.cpp
index d08c007bb..c85590d4c 100644
--- a/src/core/core_timing.cpp
+++ b/src/core/core_timing.cpp
@@ -159,6 +159,8 @@ void CoreTiming::UnscheduleEvent(const std::shared_ptr<EventType>& event_type,
159 for (auto h : to_remove) { 159 for (auto h : to_remove) {
160 event_queue.erase(h); 160 event_queue.erase(h);
161 } 161 }
162
163 event_type->sequence_number++;
162 } 164 }
163 165
164 // Force any in-progress events to finish 166 // Force any in-progress events to finish
@@ -202,9 +204,10 @@ std::optional<s64> CoreTiming::Advance() {
202 const Event& evt = event_queue.top(); 204 const Event& evt = event_queue.top();
203 205
204 if (const auto event_type{evt.type.lock()}) { 206 if (const auto event_type{evt.type.lock()}) {
205 if (evt.reschedule_time == 0) { 207 const auto evt_time = evt.time;
206 const auto evt_time = evt.time; 208 const auto evt_sequence_num = event_type->sequence_number;
207 209
210 if (evt.reschedule_time == 0) {
208 event_queue.pop(); 211 event_queue.pop();
209 212
210 basic_lock.unlock(); 213 basic_lock.unlock();
@@ -217,10 +220,15 @@ std::optional<s64> CoreTiming::Advance() {
217 basic_lock.unlock(); 220 basic_lock.unlock();
218 221
219 const auto new_schedule_time{event_type->callback( 222 const auto new_schedule_time{event_type->callback(
220 evt.time, std::chrono::nanoseconds{GetGlobalTimeNs().count() - evt.time})}; 223 evt_time, std::chrono::nanoseconds{GetGlobalTimeNs().count() - evt_time})};
221 224
222 basic_lock.lock(); 225 basic_lock.lock();
223 226
227 if (evt_sequence_num != event_type->sequence_number) {
228 // Heap handle is invalidated after external modification.
229 continue;
230 }
231
224 const auto next_schedule_time{new_schedule_time.has_value() 232 const auto next_schedule_time{new_schedule_time.has_value()
225 ? new_schedule_time.value().count() 233 ? new_schedule_time.value().count()
226 : evt.reschedule_time}; 234 : evt.reschedule_time};
diff --git a/src/core/core_timing.h b/src/core/core_timing.h
index d8cd599ee..7e4dff7f3 100644
--- a/src/core/core_timing.h
+++ b/src/core/core_timing.h
@@ -27,12 +27,15 @@ using TimedCallback = std::function<std::optional<std::chrono::nanoseconds>(
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;
36}; 39};
37 40
38enum class UnscheduleEventType { 41enum class UnscheduleEventType {