summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorGravatar bunnei2018-08-12 22:02:03 -0400
committerGravatar GitHub2018-08-12 22:02:03 -0400
commitde5d431eec05f8cc126491135e1f97f5022f7102 (patch)
treec2d1f587fa0a718748ad0245dcbbeb14a4e2d4fc /src/core
parentMerge pull request #1040 from bunnei/xmad (diff)
parentKernel/Mutex: Don't duplicate threads in the mutex waiter list. (diff)
downloadyuzu-de5d431eec05f8cc126491135e1f97f5022f7102.tar.gz
yuzu-de5d431eec05f8cc126491135e1f97f5022f7102.tar.xz
yuzu-de5d431eec05f8cc126491135e1f97f5022f7102.zip
Merge pull request #1041 from Subv/duplicated_mutex
Kernel/Mutex: Don't duplicate threads in the mutex waiter list.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/hle/kernel/svc.cpp3
-rw-r--r--src/core/hle/kernel/thread.cpp21
2 files changed, 22 insertions, 2 deletions
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp
index 5db2db687..5818cc06d 100644
--- a/src/core/hle/kernel/svc.cpp
+++ b/src/core/hle/kernel/svc.cpp
@@ -706,8 +706,7 @@ static ResultCode SignalProcessWideKey(VAddr condition_variable_addr, s32 target
706 Handle owner_handle = static_cast<Handle>(mutex_val & Mutex::MutexOwnerMask); 706 Handle owner_handle = static_cast<Handle>(mutex_val & Mutex::MutexOwnerMask);
707 auto owner = g_handle_table.Get<Thread>(owner_handle); 707 auto owner = g_handle_table.Get<Thread>(owner_handle);
708 ASSERT(owner); 708 ASSERT(owner);
709 ASSERT(thread->status != ThreadStatus::Running); 709 ASSERT(thread->status == ThreadStatus::WaitMutex);
710 thread->status = ThreadStatus::WaitMutex;
711 thread->wakeup_callback = nullptr; 710 thread->wakeup_callback = nullptr;
712 711
713 owner->AddMutexWaiter(thread); 712 owner->AddMutexWaiter(thread);
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp
index b9022feae..40918ca81 100644
--- a/src/core/hle/kernel/thread.cpp
+++ b/src/core/hle/kernel/thread.cpp
@@ -419,12 +419,33 @@ VAddr Thread::GetCommandBufferAddress() const {
419} 419}
420 420
421void Thread::AddMutexWaiter(SharedPtr<Thread> thread) { 421void Thread::AddMutexWaiter(SharedPtr<Thread> thread) {
422 if (thread->lock_owner == this) {
423 // If the thread is already waiting for this thread to release the mutex, ensure that the
424 // waiters list is consistent and return without doing anything.
425 auto itr = std::find(wait_mutex_threads.begin(), wait_mutex_threads.end(), thread);
426 ASSERT(itr != wait_mutex_threads.end());
427 return;
428 }
429
430 // A thread can't wait on two different mutexes at the same time.
431 ASSERT(thread->lock_owner == nullptr);
432
433 // Ensure that the thread is not already in the list of mutex waiters
434 auto itr = std::find(wait_mutex_threads.begin(), wait_mutex_threads.end(), thread);
435 ASSERT(itr == wait_mutex_threads.end());
436
422 thread->lock_owner = this; 437 thread->lock_owner = this;
423 wait_mutex_threads.emplace_back(std::move(thread)); 438 wait_mutex_threads.emplace_back(std::move(thread));
424 UpdatePriority(); 439 UpdatePriority();
425} 440}
426 441
427void Thread::RemoveMutexWaiter(SharedPtr<Thread> thread) { 442void Thread::RemoveMutexWaiter(SharedPtr<Thread> thread) {
443 ASSERT(thread->lock_owner == this);
444
445 // Ensure that the thread is in the list of mutex waiters
446 auto itr = std::find(wait_mutex_threads.begin(), wait_mutex_threads.end(), thread);
447 ASSERT(itr != wait_mutex_threads.end());
448
428 boost::remove_erase(wait_mutex_threads, thread); 449 boost::remove_erase(wait_mutex_threads, thread);
429 thread->lock_owner = nullptr; 450 thread->lock_owner = nullptr;
430 UpdatePriority(); 451 UpdatePriority();