From dde02f79af45fc01d747254eefbe680e580c3d45 Mon Sep 17 00:00:00 2001 From: bunnei Date: Sun, 18 Jan 2015 15:45:01 -0500 Subject: Mutex: Fix a bug where the thread should not wait if it already has the mutex. --- src/core/hle/kernel/mutex.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/core/hle/kernel/mutex.cpp') diff --git a/src/core/hle/kernel/mutex.cpp b/src/core/hle/kernel/mutex.cpp index 4a1eaca3..6cd14037 100644 --- a/src/core/hle/kernel/mutex.cpp +++ b/src/core/hle/kernel/mutex.cpp @@ -25,6 +25,7 @@ public: bool locked; ///< Current locked state Handle lock_thread; ///< Handle to thread that currently has mutex std::string name; ///< Name of mutex (optional) + SharedPtr current_thread; ///< Thread that has acquired the mutex ResultVal Wait() override; ResultVal Acquire() override; @@ -43,6 +44,7 @@ static MutexMap g_mutex_held_locks; void MutexAcquireLock(Mutex* mutex, Handle thread = GetCurrentThread()->GetHandle()) { g_mutex_held_locks.insert(std::make_pair(thread, mutex->GetHandle())); mutex->lock_thread = thread; + mutex->current_thread = Kernel::g_handle_table.Get(thread); } /** @@ -132,6 +134,7 @@ Mutex* CreateMutex(Handle& handle, bool initial_locked, const std::string& name) mutex->locked = mutex->initial_locked = initial_locked; mutex->name = name; + mutex->current_thread = nullptr; // Acquire mutex with current thread if initialized as locked... if (mutex->locked) { @@ -157,7 +160,7 @@ Handle CreateMutex(bool initial_locked, const std::string& name) { } ResultVal Mutex::Wait() { - return MakeResult(locked); + return MakeResult(locked && (current_thread != GetCurrentThread())); } ResultVal Mutex::Acquire() { -- cgit v1.2.3