diff options
author | bunnei <bunneidev@gmail.com> | 2015-01-15 01:22:50 +0100 |
---|---|---|
committer | bunnei <bunneidev@gmail.com> | 2015-01-22 00:41:00 +0100 |
commit | c22bac6398ff1705992fc44b2c29775c84cff662 (patch) | |
tree | e20da7e6e1824c19b7ced73f43815397749ffae7 /src/core/hle/kernel/mutex.cpp | |
parent | Merge pull request #491 from archshift/hidspvr (diff) | |
download | yuzu-c22bac6398ff1705992fc44b2c29775c84cff662.tar yuzu-c22bac6398ff1705992fc44b2c29775c84cff662.tar.gz yuzu-c22bac6398ff1705992fc44b2c29775c84cff662.tar.bz2 yuzu-c22bac6398ff1705992fc44b2c29775c84cff662.tar.lz yuzu-c22bac6398ff1705992fc44b2c29775c84cff662.tar.xz yuzu-c22bac6398ff1705992fc44b2c29775c84cff662.tar.zst yuzu-c22bac6398ff1705992fc44b2c29775c84cff662.zip |
Diffstat (limited to 'src/core/hle/kernel/mutex.cpp')
-rw-r--r-- | src/core/hle/kernel/mutex.cpp | 29 |
1 files changed, 6 insertions, 23 deletions
diff --git a/src/core/hle/kernel/mutex.cpp b/src/core/hle/kernel/mutex.cpp index 853a5dd74..35d829606 100644 --- a/src/core/hle/kernel/mutex.cpp +++ b/src/core/hle/kernel/mutex.cpp @@ -13,7 +13,7 @@ namespace Kernel { -class Mutex : public Object { +class Mutex : public WaitObject { public: std::string GetTypeName() const override { return "Mutex"; } std::string GetName() const override { return name; } @@ -24,7 +24,6 @@ public: bool initial_locked; ///< Initial lock state when mutex was created bool locked; ///< Current locked state Handle lock_thread; ///< Handle to thread that currently has mutex - std::vector<Handle> waiting_threads; ///< Threads that are waiting for the mutex std::string name; ///< Name of mutex (optional) ResultVal<bool> WaitSynchronization() override; @@ -45,36 +44,20 @@ void MutexAcquireLock(Mutex* mutex, Handle thread = GetCurrentThread()->GetHandl mutex->lock_thread = thread; } -bool ReleaseMutexForThread(Mutex* mutex, Handle thread_handle) { - MutexAcquireLock(mutex, thread_handle); - - Thread* thread = Kernel::g_handle_table.Get<Thread>(thread_handle).get(); - if (thread == nullptr) { - LOG_ERROR(Kernel, "Called with invalid handle: %08X", thread_handle); - return false; - } - - thread->ResumeFromWait(); - return true; -} - /** * Resumes a thread waiting for the specified mutex * @param mutex The mutex that some thread is waiting on */ void ResumeWaitingThread(Mutex* mutex) { // Find the next waiting thread for the mutex... - if (mutex->waiting_threads.empty()) { + auto next_thread = mutex->ResumeNextThread(); + if (next_thread != nullptr) { + MutexAcquireLock(mutex, next_thread->GetHandle()); + } else { // Reset mutex lock thread handle, nothing is waiting mutex->locked = false; mutex->lock_thread = -1; } - else { - // Resume the next waiting thread and re-lock the mutex - std::vector<Handle>::iterator iter = mutex->waiting_threads.begin(); - ReleaseMutexForThread(mutex, *iter); - mutex->waiting_threads.erase(iter); - } } void MutexEraseLock(Mutex* mutex) { @@ -175,7 +158,7 @@ Handle CreateMutex(bool initial_locked, const std::string& name) { ResultVal<bool> Mutex::WaitSynchronization() { bool wait = locked; if (locked) { - waiting_threads.push_back(GetCurrentThread()->GetHandle()); + AddWaitingThread(GetCurrentThread()); Kernel::WaitCurrentThread(WAITTYPE_MUTEX, this); } else { // Lock the mutex when the first thread accesses it |