From 504472af4e0343e557f9127f7863f0d64df2e4fe Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Wed, 7 Apr 2021 10:19:35 -0700 Subject: [PATCH] kern: update KConditionVariable::WaitForAddress/Wait --- .../source/kern_k_condition_variable.cpp | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/libraries/libmesosphere/source/kern_k_condition_variable.cpp b/libraries/libmesosphere/source/kern_k_condition_variable.cpp index ba25f35c4..7e9a4499f 100644 --- a/libraries/libmesosphere/source/kern_k_condition_variable.cpp +++ b/libraries/libmesosphere/source/kern_k_condition_variable.cpp @@ -102,14 +102,13 @@ namespace ams::kern { } } MESOSPHERE_ASSERT(owner_thread.IsNotNull()); - } - /* Remove the thread as a waiter from the lock owner. */ - { - KScopedSchedulerLock sl; - KThread *owner_thread = cur_thread->GetLockOwner(); - if (owner_thread != nullptr) { - owner_thread->RemoveWaiter(cur_thread); + /* Remove the thread as a waiter from the lock owner. */ + { + KScopedSchedulerLock sl; + if (KThread *mutex_owner = cur_thread->GetLockOwner(); mutex_owner != nullptr) { + mutex_owner->RemoveWaiter(cur_thread); + } } } @@ -250,11 +249,6 @@ namespace ams::kern { } } - /* Cancel the timer wait. */ - if (timer != nullptr) { - timer->CancelTask(cur_thread); - } - /* Remove from the condition variable. */ { KScopedSchedulerLock sl; @@ -269,6 +263,11 @@ namespace ams::kern { } } + /* Cancel the timer wait. */ + if (timer != nullptr) { + timer->CancelTask(cur_thread); + } + /* Get the result. */ KSynchronizationObject *dummy; return cur_thread->GetWaitResult(std::addressof(dummy));