diff options
author | bunnei <bunneidev@gmail.com> | 2015-02-10 04:06:09 +0100 |
---|---|---|
committer | bunnei <bunneidev@gmail.com> | 2015-02-10 04:06:09 +0100 |
commit | 1b0bf00cbcadfc4cca0a3d16efac8b85a4bd71e5 (patch) | |
tree | cf72fdea8a5f5e40c0ee07a8b7d705966a19a58a /src/core/hle/kernel/mutex.cpp | |
parent | WaitSynch: Always reschedule (verified behavior on hw). (diff) | |
download | yuzu-1b0bf00cbcadfc4cca0a3d16efac8b85a4bd71e5.tar yuzu-1b0bf00cbcadfc4cca0a3d16efac8b85a4bd71e5.tar.gz yuzu-1b0bf00cbcadfc4cca0a3d16efac8b85a4bd71e5.tar.bz2 yuzu-1b0bf00cbcadfc4cca0a3d16efac8b85a4bd71e5.tar.lz yuzu-1b0bf00cbcadfc4cca0a3d16efac8b85a4bd71e5.tar.xz yuzu-1b0bf00cbcadfc4cca0a3d16efac8b85a4bd71e5.tar.zst yuzu-1b0bf00cbcadfc4cca0a3d16efac8b85a4bd71e5.zip |
Diffstat (limited to 'src/core/hle/kernel/mutex.cpp')
-rw-r--r-- | src/core/hle/kernel/mutex.cpp | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/src/core/hle/kernel/mutex.cpp b/src/core/hle/kernel/mutex.cpp index 9f7166ca4..a811db392 100644 --- a/src/core/hle/kernel/mutex.cpp +++ b/src/core/hle/kernel/mutex.cpp @@ -21,7 +21,7 @@ namespace Kernel { */ static void ResumeWaitingThread(Mutex* mutex) { // Reset mutex lock thread handle, nothing is waiting - mutex->locked = false; + mutex->lock_count = 0; mutex->holding_thread = nullptr; // Find the next waiting thread for the mutex... @@ -44,8 +44,7 @@ Mutex::~Mutex() {} SharedPtr<Mutex> Mutex::Create(bool initial_locked, std::string name) { SharedPtr<Mutex> mutex(new Mutex); - mutex->initial_locked = initial_locked; - mutex->locked = false; + mutex->lock_count = 0; mutex->name = std::move(name); mutex->holding_thread = nullptr; @@ -57,7 +56,7 @@ SharedPtr<Mutex> Mutex::Create(bool initial_locked, std::string name) { } bool Mutex::ShouldWait() { - return locked && holding_thread != GetCurrentThread(); + return lock_count > 0 && holding_thread != GetCurrentThread();; } void Mutex::Acquire() { @@ -66,21 +65,27 @@ void Mutex::Acquire() { void Mutex::Acquire(SharedPtr<Thread> thread) { _assert_msg_(Kernel, !ShouldWait(), "object unavailable!"); - if (locked) - return; - locked = true; + // Actually "acquire" the mutex only if we don't already have it... + if (lock_count == 0) { + thread->held_mutexes.insert(this); + holding_thread = std::move(thread); + } - thread->held_mutexes.insert(this); - holding_thread = std::move(thread); + lock_count++; } void Mutex::Release() { - if (!locked) - return; - - holding_thread->held_mutexes.erase(this); - ResumeWaitingThread(this); + // Only release if the mutex is held... + if (lock_count > 0) { + lock_count--; + + // Yield to the next thread only if we've fully released the mutex... + if (lock_count == 0) { + holding_thread->held_mutexes.erase(this); + ResumeWaitingThread(this); + } + } } } // namespace |