summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/mutex.cpp
diff options
context:
space:
mode:
authorGravatar Subv2014-12-07 15:57:28 -0500
committerGravatar Subv2014-12-07 15:57:28 -0500
commitbc318c464bbe1a33e37312339d25c56021c444e8 (patch)
tree4d77ce76bcaea3d7afe54eae526beca2e315bf77 /src/core/hle/kernel/mutex.cpp
parentMutex: Release all held mutexes when a thread exits. (diff)
downloadyuzu-bc318c464bbe1a33e37312339d25c56021c444e8.tar.gz
yuzu-bc318c464bbe1a33e37312339d25c56021c444e8.tar.xz
yuzu-bc318c464bbe1a33e37312339d25c56021c444e8.zip
Mutex: Remove some forward declarations
Moved Mutex::WaitSynchronization to the end of the file.
Diffstat (limited to 'src/core/hle/kernel/mutex.cpp')
-rw-r--r--src/core/hle/kernel/mutex.cpp31
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
14namespace Kernel { 14namespace Kernel {
15 15
16class Mutex;
17void MutexAcquireLock(Mutex* mutex, Handle thread = GetCurrentThreadHandle());
18
19class Mutex : public Object { 16class Mutex : public Object {
20public: 17public:
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 */
57void MutexAcquireLock(Mutex* mutex, Handle thread) { 43void 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
167ResultVal<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