summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/mutex.cpp
diff options
context:
space:
mode:
authorGravatar bunnei2015-01-18 15:45:01 -0500
committerGravatar bunnei2015-01-21 20:47:46 -0500
commitdde02f79af45fc01d747254eefbe680e580c3d45 (patch)
treebd91ce3b8e2db4280aaff1f00173911c32400d1d /src/core/hle/kernel/mutex.cpp
parentKernel: Moved Wait and Acquire to WaitObject, added way to retrieve a WaitObj... (diff)
downloadyuzu-dde02f79af45fc01d747254eefbe680e580c3d45.tar.gz
yuzu-dde02f79af45fc01d747254eefbe680e580c3d45.tar.xz
yuzu-dde02f79af45fc01d747254eefbe680e580c3d45.zip
Mutex: Fix a bug where the thread should not wait if it already has the mutex.
Diffstat (limited to 'src/core/hle/kernel/mutex.cpp')
-rw-r--r--src/core/hle/kernel/mutex.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/core/hle/kernel/mutex.cpp b/src/core/hle/kernel/mutex.cpp
index 4a1eaca37..6cd140376 100644
--- a/src/core/hle/kernel/mutex.cpp
+++ b/src/core/hle/kernel/mutex.cpp
@@ -25,6 +25,7 @@ public:
25 bool locked; ///< Current locked state 25 bool locked; ///< Current locked state
26 Handle lock_thread; ///< Handle to thread that currently has mutex 26 Handle lock_thread; ///< Handle to thread that currently has mutex
27 std::string name; ///< Name of mutex (optional) 27 std::string name; ///< Name of mutex (optional)
28 SharedPtr<Thread> current_thread; ///< Thread that has acquired the mutex
28 29
29 ResultVal<bool> Wait() override; 30 ResultVal<bool> Wait() override;
30 ResultVal<bool> Acquire() override; 31 ResultVal<bool> Acquire() override;
@@ -43,6 +44,7 @@ static MutexMap g_mutex_held_locks;
43void MutexAcquireLock(Mutex* mutex, Handle thread = GetCurrentThread()->GetHandle()) { 44void MutexAcquireLock(Mutex* mutex, Handle thread = GetCurrentThread()->GetHandle()) {
44 g_mutex_held_locks.insert(std::make_pair(thread, mutex->GetHandle())); 45 g_mutex_held_locks.insert(std::make_pair(thread, mutex->GetHandle()));
45 mutex->lock_thread = thread; 46 mutex->lock_thread = thread;
47 mutex->current_thread = Kernel::g_handle_table.Get<Thread>(thread);
46} 48}
47 49
48/** 50/**
@@ -132,6 +134,7 @@ Mutex* CreateMutex(Handle& handle, bool initial_locked, const std::string& name)
132 134
133 mutex->locked = mutex->initial_locked = initial_locked; 135 mutex->locked = mutex->initial_locked = initial_locked;
134 mutex->name = name; 136 mutex->name = name;
137 mutex->current_thread = nullptr;
135 138
136 // Acquire mutex with current thread if initialized as locked... 139 // Acquire mutex with current thread if initialized as locked...
137 if (mutex->locked) { 140 if (mutex->locked) {
@@ -157,7 +160,7 @@ Handle CreateMutex(bool initial_locked, const std::string& name) {
157} 160}
158 161
159ResultVal<bool> Mutex::Wait() { 162ResultVal<bool> Mutex::Wait() {
160 return MakeResult<bool>(locked); 163 return MakeResult<bool>(locked && (current_thread != GetCurrentThread()));
161} 164}
162 165
163ResultVal<bool> Mutex::Acquire() { 166ResultVal<bool> Mutex::Acquire() {