diff options
Diffstat (limited to 'src/core/hle/kernel/mutex.cpp')
| -rw-r--r-- | src/core/hle/kernel/mutex.cpp | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/src/core/hle/kernel/mutex.cpp b/src/core/hle/kernel/mutex.cpp index 01de3c510..5a173e129 100644 --- a/src/core/hle/kernel/mutex.cpp +++ b/src/core/hle/kernel/mutex.cpp | |||
| @@ -13,9 +13,6 @@ | |||
| 13 | 13 | ||
| 14 | namespace Kernel { | 14 | namespace Kernel { |
| 15 | 15 | ||
| 16 | class Mutex; | ||
| 17 | void MutexAcquireLock(Mutex* mutex, Handle thread = GetCurrentThreadHandle()); | ||
| 18 | |||
| 19 | class Mutex : public Object { | 16 | class Mutex : public Object { |
| 20 | public: | 17 | public: |
| 21 | std::string GetTypeName() const override { return "Mutex"; } | 18 | std::string GetTypeName() const override { return "Mutex"; } |
| @@ -30,18 +27,7 @@ public: | |||
| 30 | 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 |
| 31 | std::string name; ///< Name of mutex (optional) | 28 | std::string name; ///< Name of mutex (optional) |
| 32 | 29 | ||
| 33 | ResultVal<bool> WaitSynchronization() override { | 30 | ResultVal<bool> WaitSynchronization() override; |
| 34 | bool wait = locked; | ||
| 35 | if (locked) { | ||
| 36 | Kernel::WaitCurrentThread(WAITTYPE_MUTEX, GetHandle()); | ||
| 37 | } else { | ||
| 38 | // Lock the mutex when the first thread accesses it | ||
| 39 | locked = true; | ||
| 40 | MutexAcquireLock(this); | ||
| 41 | } | ||
| 42 | |||
| 43 | return MakeResult<bool>(wait); | ||
| 44 | } | ||
| 45 | }; | 31 | }; |
| 46 | 32 | ||
| 47 | //////////////////////////////////////////////////////////////////////////////////////////////////// | 33 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| @@ -54,7 +40,7 @@ static MutexMap g_mutex_held_locks; | |||
| 54 | * @param mutex Mutex that is to be acquired | 40 | * @param mutex Mutex that is to be acquired |
| 55 | * @param thread Thread that will acquired | 41 | * @param thread Thread that will acquired |
| 56 | */ | 42 | */ |
| 57 | void MutexAcquireLock(Mutex* mutex, Handle thread) { | 43 | void MutexAcquireLock(Mutex* mutex, Handle thread = GetCurrentThreadHandle()) { |
| 58 | g_mutex_held_locks.insert(std::make_pair(thread, mutex->GetHandle())); | 44 | g_mutex_held_locks.insert(std::make_pair(thread, mutex->GetHandle())); |
| 59 | mutex->lock_thread = thread; | 45 | mutex->lock_thread = thread; |
| 60 | } | 46 | } |
| @@ -178,4 +164,17 @@ Handle CreateMutex(bool initial_locked, const std::string& name) { | |||
| 178 | return handle; | 164 | return handle; |
| 179 | } | 165 | } |
| 180 | 166 | ||
| 167 | ResultVal<bool> Mutex::WaitSynchronization() { | ||
| 168 | bool wait = locked; | ||
| 169 | if (locked) { | ||
| 170 | Kernel::WaitCurrentThread(WAITTYPE_MUTEX, GetHandle()); | ||
| 171 | } | ||
| 172 | else { | ||
| 173 | // Lock the mutex when the first thread accesses it | ||
| 174 | locked = true; | ||
| 175 | MutexAcquireLock(this); | ||
| 176 | } | ||
| 177 | |||
| 178 | return MakeResult<bool>(wait); | ||
| 179 | } | ||
| 181 | } // namespace | 180 | } // namespace |