summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/mutex.cpp
diff options
context:
space:
mode:
authorGravatar bunnei2015-01-09 12:59:35 -0500
committerGravatar bunnei2015-01-09 12:59:35 -0500
commit6ae12424df58f0ea171fc75ca4b700ab1fffc192 (patch)
tree93d87f3cb19d08541c6b8f8a9e0ceb730a2b13d9 /src/core/hle/kernel/mutex.cpp
parentMerge pull request #436 from kevinhartman/system-core (diff)
parentThread: Fix nullptr access in a logging function (diff)
downloadyuzu-6ae12424df58f0ea171fc75ca4b700ab1fffc192.tar.gz
yuzu-6ae12424df58f0ea171fc75ca4b700ab1fffc192.tar.xz
yuzu-6ae12424df58f0ea171fc75ca4b700ab1fffc192.zip
Merge pull request #444 from yuriks/handle-reform2
Kernel Lifetime Reform Pt. 2
Diffstat (limited to 'src/core/hle/kernel/mutex.cpp')
-rw-r--r--src/core/hle/kernel/mutex.cpp19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/core/hle/kernel/mutex.cpp b/src/core/hle/kernel/mutex.cpp
index 3dfeffc9b..7d008f6cc 100644
--- a/src/core/hle/kernel/mutex.cpp
+++ b/src/core/hle/kernel/mutex.cpp
@@ -40,14 +40,21 @@ static MutexMap g_mutex_held_locks;
40 * @param mutex Mutex that is to be acquired 40 * @param mutex Mutex that is to be acquired
41 * @param thread Thread that will acquired 41 * @param thread Thread that will acquired
42 */ 42 */
43void MutexAcquireLock(Mutex* mutex, Handle thread = GetCurrentThreadHandle()) { 43void MutexAcquireLock(Mutex* mutex, Handle thread = GetCurrentThread()->GetHandle()) {
44 g_mutex_held_locks.insert(std::make_pair(thread, mutex->GetHandle())); 44 g_mutex_held_locks.insert(std::make_pair(thread, mutex->GetHandle()));
45 mutex->lock_thread = thread; 45 mutex->lock_thread = thread;
46} 46}
47 47
48bool ReleaseMutexForThread(Mutex* mutex, Handle thread) { 48bool ReleaseMutexForThread(Mutex* mutex, Handle thread_handle) {
49 MutexAcquireLock(mutex, thread); 49 MutexAcquireLock(mutex, thread_handle);
50 Kernel::ResumeThreadFromWait(thread); 50
51 Thread* thread = Kernel::g_handle_table.Get<Thread>(thread_handle);
52 if (thread == nullptr) {
53 LOG_ERROR(Kernel, "Called with invalid handle: %08X", thread_handle);
54 return false;
55 }
56
57 thread->ResumeFromWait();
51 return true; 58 return true;
52} 59}
53 60
@@ -168,8 +175,8 @@ Handle CreateMutex(bool initial_locked, const std::string& name) {
168ResultVal<bool> Mutex::WaitSynchronization() { 175ResultVal<bool> Mutex::WaitSynchronization() {
169 bool wait = locked; 176 bool wait = locked;
170 if (locked) { 177 if (locked) {
171 waiting_threads.push_back(GetCurrentThreadHandle()); 178 waiting_threads.push_back(GetCurrentThread()->GetHandle());
172 Kernel::WaitCurrentThread(WAITTYPE_MUTEX, GetHandle()); 179 Kernel::WaitCurrentThread(WAITTYPE_MUTEX, this);
173 } else { 180 } else {
174 // Lock the mutex when the first thread accesses it 181 // Lock the mutex when the first thread accesses it
175 locked = true; 182 locked = true;