From 331fa1d00d5bd7fcd0389816e3ef356df32ff86e Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Wed, 2 Dec 2020 01:28:21 -0800 Subject: [PATCH] kern: update KConditionVariable to support new has_waiter_flag rules --- .../source/kern_k_condition_variable.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/libraries/libmesosphere/source/kern_k_condition_variable.cpp b/libraries/libmesosphere/source/kern_k_condition_variable.cpp index 56ffaf491..e86aaad29 100644 --- a/libraries/libmesosphere/source/kern_k_condition_variable.cpp +++ b/libraries/libmesosphere/source/kern_k_condition_variable.cpp @@ -194,6 +194,12 @@ namespace ams::kern { target_thread->ClearConditionVariable(); ++num_waiters; } + + /* If we have no waiters, clear the has waiter flag. */ + if (it == this->tree.end() || it->GetConditionVariableKey() != cv_key) { + const u32 has_waiter_flag = 0; + WriteToUser(cv_key, std::addressof(has_waiter_flag)); + } } /* Close threads in the array. */ @@ -244,6 +250,13 @@ namespace ams::kern { next_owner_thread->Wakeup(); } + /* Write to the cv key. */ + { + const u32 has_waiter_flag = 1; + WriteToUser(key, std::addressof(has_waiter_flag)); + cpu::DataMemoryBarrier(); + } + /* Write the value to userspace. */ if (!WriteToUser(addr, std::addressof(next_value))) { slp.CancelSleep();