summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/core_timing.cpp10
-rw-r--r--src/core/core_timing.h1
-rw-r--r--src/core/hle/kernel/thread.cpp2
3 files changed, 12 insertions, 1 deletions
diff --git a/src/core/core_timing.cpp b/src/core/core_timing.cpp
index f977d1b32..7953c8720 100644
--- a/src/core/core_timing.cpp
+++ b/src/core/core_timing.cpp
@@ -56,6 +56,9 @@ static u64 event_fifo_id;
56// to the event_queue by the emu thread 56// to the event_queue by the emu thread
57static Common::MPSCQueue<Event, false> ts_queue; 57static Common::MPSCQueue<Event, false> ts_queue;
58 58
59// the queue for unscheduling the events from other threads threadsafe
60static Common::MPSCQueue<std::pair<const EventType*, u64>, false> unschedule_queue;
61
59constexpr int MAX_SLICE_LENGTH = 20000; 62constexpr int MAX_SLICE_LENGTH = 20000;
60 63
61static s64 idled_cycles; 64static s64 idled_cycles;
@@ -158,6 +161,10 @@ void UnscheduleEvent(const EventType* event_type, u64 userdata) {
158 } 161 }
159} 162}
160 163
164void UnscheduleEventThreadsafe(const EventType* event_type, u64 userdata) {
165 unschedule_queue.Push(std::make_pair(event_type, userdata));
166}
167
161void RemoveEvent(const EventType* event_type) { 168void RemoveEvent(const EventType* event_type) {
162 auto itr = std::remove_if(event_queue.begin(), event_queue.end(), 169 auto itr = std::remove_if(event_queue.begin(), event_queue.end(),
163 [&](const Event& e) { return e.type == event_type; }); 170 [&](const Event& e) { return e.type == event_type; });
@@ -194,6 +201,9 @@ void MoveEvents() {
194 201
195void Advance() { 202void Advance() {
196 MoveEvents(); 203 MoveEvents();
204 for (std::pair<const EventType*, u64> ev; unschedule_queue.Pop(ev);) {
205 UnscheduleEvent(ev.first, ev.second);
206 }
197 207
198 int cycles_executed = slice_length - downcount; 208 int cycles_executed = slice_length - downcount;
199 global_timer += cycles_executed; 209 global_timer += cycles_executed;
diff --git a/src/core/core_timing.h b/src/core/core_timing.h
index dfa161c0d..9ed757bd7 100644
--- a/src/core/core_timing.h
+++ b/src/core/core_timing.h
@@ -65,6 +65,7 @@ void ScheduleEvent(s64 cycles_into_future, const EventType* event_type, u64 user
65void ScheduleEventThreadsafe(s64 cycles_into_future, const EventType* event_type, u64 userdata); 65void ScheduleEventThreadsafe(s64 cycles_into_future, const EventType* event_type, u64 userdata);
66 66
67void UnscheduleEvent(const EventType* event_type, u64 userdata); 67void UnscheduleEvent(const EventType* event_type, u64 userdata);
68void UnscheduleEventThreadsafe(const EventType* event_type, u64 userdata);
68 69
69/// We only permit one event of each type in the queue at a time. 70/// We only permit one event of each type in the queue at a time.
70void RemoveEvent(const EventType* event_type); 71void RemoveEvent(const EventType* event_type);
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp
index a1a7867ce..cf4f94822 100644
--- a/src/core/hle/kernel/thread.cpp
+++ b/src/core/hle/kernel/thread.cpp
@@ -167,7 +167,7 @@ void Thread::WakeAfterDelay(s64 nanoseconds) {
167} 167}
168 168
169void Thread::CancelWakeupTimer() { 169void Thread::CancelWakeupTimer() {
170 CoreTiming::UnscheduleEvent(ThreadWakeupEventType, callback_handle); 170 CoreTiming::UnscheduleEventThreadsafe(ThreadWakeupEventType, callback_handle);
171} 171}
172 172
173static boost::optional<s32> GetNextProcessorId(u64 mask) { 173static boost::optional<s32> GetNextProcessorId(u64 mask) {