diff options
| author | 2015-01-17 22:23:49 -0500 | |
|---|---|---|
| committer | 2015-01-21 19:10:24 -0500 | |
| commit | aa01c57ae9d73e41b65d37860ca6fbb91caba33a (patch) | |
| tree | 904936860b1e8319ec5edc3a1e0e6c2c12f01d9f /src/core/hle/kernel/mutex.cpp | |
| parent | WaitSynchronizationN: Handle case where handles=nullptr. (diff) | |
| download | yuzu-aa01c57ae9d73e41b65d37860ca6fbb91caba33a.tar.gz yuzu-aa01c57ae9d73e41b65d37860ca6fbb91caba33a.tar.xz yuzu-aa01c57ae9d73e41b65d37860ca6fbb91caba33a.zip | |
Kernel: Separate WaitSynchronization into Wait and Acquire methods.
Diffstat (limited to 'src/core/hle/kernel/mutex.cpp')
| -rw-r--r-- | src/core/hle/kernel/mutex.cpp | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/core/hle/kernel/mutex.cpp b/src/core/hle/kernel/mutex.cpp index 78063b8f1..37e7be4e7 100644 --- a/src/core/hle/kernel/mutex.cpp +++ b/src/core/hle/kernel/mutex.cpp | |||
| @@ -26,7 +26,8 @@ public: | |||
| 26 | Handle lock_thread; ///< Handle to thread that currently has mutex | 26 | Handle lock_thread; ///< Handle to thread that currently has mutex |
| 27 | std::string name; ///< Name of mutex (optional) | 27 | std::string name; ///< Name of mutex (optional) |
| 28 | 28 | ||
| 29 | ResultVal<bool> WaitSynchronization(unsigned index) override; | 29 | ResultVal<bool> Wait(unsigned index) override; |
| 30 | ResultVal<bool> Acquire() override; | ||
| 30 | }; | 31 | }; |
| 31 | 32 | ||
| 32 | //////////////////////////////////////////////////////////////////////////////////////////////////// | 33 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| @@ -155,17 +156,25 @@ Handle CreateMutex(bool initial_locked, const std::string& name) { | |||
| 155 | return handle; | 156 | return handle; |
| 156 | } | 157 | } |
| 157 | 158 | ||
| 158 | ResultVal<bool> Mutex::WaitSynchronization(unsigned index) { | 159 | ResultVal<bool> Mutex::Wait(unsigned index) { |
| 159 | bool wait = locked; | ||
| 160 | if (locked) { | 160 | if (locked) { |
| 161 | AddWaitingThread(GetCurrentThread()); | 161 | AddWaitingThread(GetCurrentThread()); |
| 162 | Kernel::WaitCurrentThread_WaitSynchronization(WAITTYPE_MUTEX, this, index); | 162 | Kernel::WaitCurrentThread_WaitSynchronization(WAITTYPE_MUTEX, this, index); |
| 163 | } else { | 163 | } |
| 164 | |||
| 165 | return MakeResult<bool>(locked); | ||
| 166 | } | ||
| 167 | |||
| 168 | ResultVal<bool> Mutex::Acquire() { | ||
| 169 | bool res = false; | ||
| 170 | |||
| 171 | if (!locked) { | ||
| 164 | // Lock the mutex when the first thread accesses it | 172 | // Lock the mutex when the first thread accesses it |
| 165 | locked = true; | 173 | locked = true; |
| 174 | res = true; | ||
| 166 | MutexAcquireLock(this); | 175 | MutexAcquireLock(this); |
| 167 | } | 176 | } |
| 168 | 177 | ||
| 169 | return MakeResult<bool>(wait); | 178 | return MakeResult<bool>(res); |
| 170 | } | 179 | } |
| 171 | } // namespace | 180 | } // namespace |