summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/thread.cpp
diff options
context:
space:
mode:
authorGravatar bunnei2018-08-12 22:05:48 -0400
committerGravatar GitHub2018-08-12 22:05:48 -0400
commite4ed5bc83610b7538f3a8ea355a3ed2437c87671 (patch)
tree7ae20333761b95790d6d263539f8607084982b38 /src/core/hle/kernel/thread.cpp
parentMerge pull request #1041 from Subv/duplicated_mutex (diff)
parentCore/HLE: Make the 'reschedule_pending' flag atomic. (diff)
downloadyuzu-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.
Diffstat (limited to 'src/core/hle/kernel/thread.cpp')
-rw-r--r--src/core/hle/kernel/thread.cpp11
1 files changed, 9 insertions, 2 deletions
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 */
105static void ThreadWakeupCallback(u64 thread_handle, int cycles_late) { 106static 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
162void Thread::CancelWakeupTimer() { 169void Thread::CancelWakeupTimer() {