diff options
| author | 2018-08-12 22:05:48 -0400 | |
|---|---|---|
| committer | 2018-08-12 22:05:48 -0400 | |
| commit | e4ed5bc83610b7538f3a8ea355a3ed2437c87671 (patch) | |
| tree | 7ae20333761b95790d6d263539f8607084982b38 | |
| parent | Merge pull request #1041 from Subv/duplicated_mutex (diff) | |
| parent | Core/HLE: Make the 'reschedule_pending' flag atomic. (diff) | |
| download | yuzu-e4ed5bc83610b7538f3a8ea355a3ed2437c87671.tar.gz yuzu-e4ed5bc83610b7538f3a8ea355a3ed2437c87671.tar.xz yuzu-e4ed5bc83610b7538f3a8ea355a3ed2437c87671.zip | |
Merge pull request #1042 from Subv/races
Fixed a bunch of race conditions when running in multicore mode.
| -rw-r--r-- | src/core/core_cpu.cpp | 3 | ||||
| -rw-r--r-- | src/core/core_cpu.h | 2 | ||||
| -rw-r--r-- | src/core/core_timing.cpp | 2 | ||||
| -rw-r--r-- | src/core/hle/kernel/thread.cpp | 11 |
4 files changed, 13 insertions, 5 deletions
diff --git a/src/core/core_cpu.cpp b/src/core/core_cpu.cpp index 46a522fcd..9b306faf6 100644 --- a/src/core/core_cpu.cpp +++ b/src/core/core_cpu.cpp | |||
| @@ -14,6 +14,7 @@ | |||
| 14 | #include "core/core_timing.h" | 14 | #include "core/core_timing.h" |
| 15 | #include "core/hle/kernel/scheduler.h" | 15 | #include "core/hle/kernel/scheduler.h" |
| 16 | #include "core/hle/kernel/thread.h" | 16 | #include "core/hle/kernel/thread.h" |
| 17 | #include "core/hle/lock.h" | ||
| 17 | #include "core/settings.h" | 18 | #include "core/settings.h" |
| 18 | 19 | ||
| 19 | namespace Core { | 20 | namespace Core { |
| @@ -125,6 +126,8 @@ void Cpu::Reschedule() { | |||
| 125 | } | 126 | } |
| 126 | 127 | ||
| 127 | reschedule_pending = false; | 128 | reschedule_pending = false; |
| 129 | // Lock the global kernel mutex when we manipulate the HLE state | ||
| 130 | std::lock_guard<std::recursive_mutex> lock(HLE::g_hle_lock); | ||
| 128 | scheduler->Reschedule(); | 131 | scheduler->Reschedule(); |
| 129 | } | 132 | } |
| 130 | 133 | ||
diff --git a/src/core/core_cpu.h b/src/core/core_cpu.h index 976952903..56cdae194 100644 --- a/src/core/core_cpu.h +++ b/src/core/core_cpu.h | |||
| @@ -79,7 +79,7 @@ private: | |||
| 79 | std::shared_ptr<CpuBarrier> cpu_barrier; | 79 | std::shared_ptr<CpuBarrier> cpu_barrier; |
| 80 | std::shared_ptr<Kernel::Scheduler> scheduler; | 80 | std::shared_ptr<Kernel::Scheduler> scheduler; |
| 81 | 81 | ||
| 82 | bool reschedule_pending{}; | 82 | std::atomic<bool> reschedule_pending = false; |
| 83 | size_t core_index; | 83 | size_t core_index; |
| 84 | }; | 84 | }; |
| 85 | 85 | ||
diff --git a/src/core/core_timing.cpp b/src/core/core_timing.cpp index d3bb6f818..f977d1b32 100644 --- a/src/core/core_timing.cpp +++ b/src/core/core_timing.cpp | |||
| @@ -135,11 +135,9 @@ void ClearPendingEvents() { | |||
| 135 | void ScheduleEvent(s64 cycles_into_future, const EventType* event_type, u64 userdata) { | 135 | void ScheduleEvent(s64 cycles_into_future, const EventType* event_type, u64 userdata) { |
| 136 | ASSERT(event_type != nullptr); | 136 | ASSERT(event_type != nullptr); |
| 137 | s64 timeout = GetTicks() + cycles_into_future; | 137 | s64 timeout = GetTicks() + cycles_into_future; |
| 138 | |||
| 139 | // If this event needs to be scheduled before the next advance(), force one early | 138 | // If this event needs to be scheduled before the next advance(), force one early |
| 140 | if (!is_global_timer_sane) | 139 | if (!is_global_timer_sane) |
| 141 | ForceExceptionCheck(cycles_into_future); | 140 | ForceExceptionCheck(cycles_into_future); |
| 142 | |||
| 143 | event_queue.emplace_back(Event{timeout, event_fifo_id++, userdata, event_type}); | 141 | event_queue.emplace_back(Event{timeout, event_fifo_id++, userdata, event_type}); |
| 144 | std::push_heap(event_queue.begin(), event_queue.end(), std::greater<>()); | 142 | std::push_heap(event_queue.begin(), event_queue.end(), std::greater<>()); |
| 145 | } | 143 | } |
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index 40918ca81..a1a7867ce 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp | |||
| @@ -23,6 +23,7 @@ | |||
| 23 | #include "core/hle/kernel/object.h" | 23 | #include "core/hle/kernel/object.h" |
| 24 | #include "core/hle/kernel/process.h" | 24 | #include "core/hle/kernel/process.h" |
| 25 | #include "core/hle/kernel/thread.h" | 25 | #include "core/hle/kernel/thread.h" |
| 26 | #include "core/hle/lock.h" | ||
| 26 | #include "core/hle/result.h" | 27 | #include "core/hle/result.h" |
| 27 | #include "core/memory.h" | 28 | #include "core/memory.h" |
| 28 | 29 | ||
| @@ -104,6 +105,10 @@ void ExitCurrentThread() { | |||
| 104 | */ | 105 | */ |
| 105 | static void ThreadWakeupCallback(u64 thread_handle, int cycles_late) { | 106 | static void ThreadWakeupCallback(u64 thread_handle, int cycles_late) { |
| 106 | const auto proper_handle = static_cast<Handle>(thread_handle); | 107 | const auto proper_handle = static_cast<Handle>(thread_handle); |
| 108 | |||
| 109 | // Lock the global kernel mutex when we enter the kernel HLE. | ||
| 110 | std::lock_guard<std::recursive_mutex> lock(HLE::g_hle_lock); | ||
| 111 | |||
| 107 | SharedPtr<Thread> thread = wakeup_callback_handle_table.Get<Thread>(proper_handle); | 112 | SharedPtr<Thread> thread = wakeup_callback_handle_table.Get<Thread>(proper_handle); |
| 108 | if (thread == nullptr) { | 113 | if (thread == nullptr) { |
| 109 | LOG_CRITICAL(Kernel, "Callback fired for invalid thread {:08X}", proper_handle); | 114 | LOG_CRITICAL(Kernel, "Callback fired for invalid thread {:08X}", proper_handle); |
| @@ -155,8 +160,10 @@ void Thread::WakeAfterDelay(s64 nanoseconds) { | |||
| 155 | if (nanoseconds == -1) | 160 | if (nanoseconds == -1) |
| 156 | return; | 161 | return; |
| 157 | 162 | ||
| 158 | CoreTiming::ScheduleEvent(CoreTiming::nsToCycles(nanoseconds), ThreadWakeupEventType, | 163 | // This function might be called from any thread so we have to be cautious and use the |
| 159 | callback_handle); | 164 | // thread-safe version of ScheduleEvent. |
| 165 | CoreTiming::ScheduleEventThreadsafe(CoreTiming::nsToCycles(nanoseconds), ThreadWakeupEventType, | ||
| 166 | callback_handle); | ||
| 160 | } | 167 | } |
| 161 | 168 | ||
| 162 | void Thread::CancelWakeupTimer() { | 169 | void Thread::CancelWakeupTimer() { |