summaryrefslogtreecommitdiffstats
path: root/src/core/hle/kernel/thread.cpp
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2018-08-13 04:02:03 +0200
committerGitHub <noreply@github.com>2018-08-13 04:02:03 +0200
commitde5d431eec05f8cc126491135e1f97f5022f7102 (patch)
treec2d1f587fa0a718748ad0245dcbbeb14a4e2d4fc /src/core/hle/kernel/thread.cpp
parentMerge pull request #1040 from bunnei/xmad (diff)
parentKernel/Mutex: Don't duplicate threads in the mutex waiter list. (diff)
downloadyuzu-de5d431eec05f8cc126491135e1f97f5022f7102.tar
yuzu-de5d431eec05f8cc126491135e1f97f5022f7102.tar.gz
yuzu-de5d431eec05f8cc126491135e1f97f5022f7102.tar.bz2
yuzu-de5d431eec05f8cc126491135e1f97f5022f7102.tar.lz
yuzu-de5d431eec05f8cc126491135e1f97f5022f7102.tar.xz
yuzu-de5d431eec05f8cc126491135e1f97f5022f7102.tar.zst
yuzu-de5d431eec05f8cc126491135e1f97f5022f7102.zip
Diffstat (limited to 'src/core/hle/kernel/thread.cpp')
-rw-r--r--src/core/hle/kernel/thread.cpp21
1 files changed, 21 insertions, 0 deletions
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 {
}
void Thread::AddMutexWaiter(SharedPtr<Thread> thread) {
+ if (thread->lock_owner == this) {
+ // If the thread is already waiting for this thread to release the mutex, ensure that the
+ // waiters list is consistent and return without doing anything.
+ auto itr = std::find(wait_mutex_threads.begin(), wait_mutex_threads.end(), thread);
+ ASSERT(itr != wait_mutex_threads.end());
+ return;
+ }
+
+ // A thread can't wait on two different mutexes at the same time.
+ ASSERT(thread->lock_owner == nullptr);
+
+ // Ensure that the thread is not already in the list of mutex waiters
+ auto itr = std::find(wait_mutex_threads.begin(), wait_mutex_threads.end(), thread);
+ ASSERT(itr == wait_mutex_threads.end());
+
thread->lock_owner = this;
wait_mutex_threads.emplace_back(std::move(thread));
UpdatePriority();
}
void Thread::RemoveMutexWaiter(SharedPtr<Thread> thread) {
+ ASSERT(thread->lock_owner == this);
+
+ // Ensure that the thread is in the list of mutex waiters
+ auto itr = std::find(wait_mutex_threads.begin(), wait_mutex_threads.end(), thread);
+ ASSERT(itr != wait_mutex_threads.end());
+
boost::remove_erase(wait_mutex_threads, thread);
thread->lock_owner = nullptr;
UpdatePriority();