summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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:
27 std::vector<Handle> waiting_threads; ///< Threads that are waiting for the mutex 27 std::vector<Handle> waiting_threads; ///< Threads that are waiting for the mutex
28 std::string name; ///< Name of mutex (optional) 28 std::string name; ///< Name of mutex (optional)
29 29
30 ResultVal<bool> SyncRequest() override {
31 // TODO(bunnei): ImplementMe
32 locked = true;
33 return MakeResult<bool>(false);
34 }
35
36 ResultVal<bool> WaitSynchronization() override { 30 ResultVal<bool> WaitSynchronization() override {
37 // TODO(bunnei): ImplementMe
38 bool wait = locked; 31 bool wait = locked;
39 if (locked) { 32 if (locked) {
40 Kernel::WaitCurrentThread(WAITTYPE_MUTEX, GetHandle()); 33 Kernel::WaitCurrentThread(WAITTYPE_MUTEX, GetHandle());
34 } else {
35 // Lock the mutex when the first thread accesses it
36 locked = true;
41 } 37 }
42 38
43 return MakeResult<bool>(wait); 39 return MakeResult<bool>(wait);
@@ -90,16 +86,17 @@ bool ReleaseMutex(Mutex* mutex) {
90 MutexEraseLock(mutex); 86 MutexEraseLock(mutex);
91 87
92 // Find the next waiting thread for the mutex... 88 // Find the next waiting thread for the mutex...
93 while (!mutex->waiting_threads.empty()) { 89 if (mutex->waiting_threads.empty()) {
90 // Reset mutex lock thread handle, nothing is waiting
91 mutex->locked = false;
92 mutex->lock_thread = -1;
93 } else {
94 // Resume the next waiting thread and re-lock the mutex
94 std::vector<Handle>::iterator iter = mutex->waiting_threads.begin(); 95 std::vector<Handle>::iterator iter = mutex->waiting_threads.begin();
95 ReleaseMutexForThread(mutex, *iter); 96 ReleaseMutexForThread(mutex, *iter);
96 mutex->waiting_threads.erase(iter); 97 mutex->waiting_threads.erase(iter);
97 } 98 }
98 99
99 // Reset mutex lock thread handle, nothing is waiting
100 mutex->locked = false;
101 mutex->lock_thread = -1;
102
103 return true; 100 return true;
104} 101}
105 102