summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
authorSubv <subv2112@gmail.com>2014-12-06 05:40:43 +0100
committerSubv <subv2112@gmail.com>2014-12-06 05:40:43 +0100
commite3c8e4901c51e2ba172f0e1cec0a07dd56f25311 (patch)
treef65aad244d7e207a83338cd3c6caac6838c7625a /src/core
parentMerge pull request #250 from Subv/cbranch_2 (diff)
downloadyuzu-e3c8e4901c51e2ba172f0e1cec0a07dd56f25311.tar
yuzu-e3c8e4901c51e2ba172f0e1cec0a07dd56f25311.tar.gz
yuzu-e3c8e4901c51e2ba172f0e1cec0a07dd56f25311.tar.bz2
yuzu-e3c8e4901c51e2ba172f0e1cec0a07dd56f25311.tar.lz
yuzu-e3c8e4901c51e2ba172f0e1cec0a07dd56f25311.tar.xz
yuzu-e3c8e4901c51e2ba172f0e1cec0a07dd56f25311.tar.zst
yuzu-e3c8e4901c51e2ba172f0e1cec0a07dd56f25311.zip
Diffstat (limited to 'src/core')
-rw-r--r--src/core/hle/kernel/mutex.cpp21
1 files changed, 9 insertions, 12 deletions
diff --git a/src/core/hle/kernel/mutex.cpp b/src/core/hle/kernel/mutex.cpp
index d07e9761b..17850c1b3 100644
--- a/src/core/hle/kernel/mutex.cpp
+++ b/src/core/hle/kernel/mutex.cpp
@@ -27,17 +27,13 @@ public:
std::vector<Handle> waiting_threads; ///< Threads that are waiting for the mutex
std::string name; ///< Name of mutex (optional)
- ResultVal<bool> SyncRequest() override {
- // TODO(bunnei): ImplementMe
- locked = true;
- return MakeResult<bool>(false);
- }
-
ResultVal<bool> WaitSynchronization() override {
- // TODO(bunnei): ImplementMe
bool wait = locked;
if (locked) {
Kernel::WaitCurrentThread(WAITTYPE_MUTEX, GetHandle());
+ } else {
+ // Lock the mutex when the first thread accesses it
+ locked = true;
}
return MakeResult<bool>(wait);
@@ -90,16 +86,17 @@ bool ReleaseMutex(Mutex* mutex) {
MutexEraseLock(mutex);
// Find the next waiting thread for the mutex...
- while (!mutex->waiting_threads.empty()) {
+ if (mutex->waiting_threads.empty()) {
+ // 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);
}
- // Reset mutex lock thread handle, nothing is waiting
- mutex->locked = false;
- mutex->lock_thread = -1;
-
return true;
}