From a75c16226e64c3a086db4538f93186ba626a7b6b Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Sat, 15 Aug 2020 03:02:09 -0700 Subject: [PATCH] kern: correct thread termination atomicity --- libraries/libmesosphere/source/kern_k_thread.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/libraries/libmesosphere/source/kern_k_thread.cpp b/libraries/libmesosphere/source/kern_k_thread.cpp index a1cbbbe8a..eb9fc571b 100644 --- a/libraries/libmesosphere/source/kern_k_thread.cpp +++ b/libraries/libmesosphere/source/kern_k_thread.cpp @@ -1099,13 +1099,7 @@ namespace ams::kern { const bool first_request = [&] ALWAYS_INLINE_LAMBDA () -> bool { /* Perform an atomic compare-and-swap from false to true. */ bool expected = false; - do { - if (expected) { - return false; - } - } while (!this->termination_requested.compare_exchange_weak(expected, true)); - - return true; + return this->termination_requested.compare_exchange_strong(expected, true); }(); /* If this is the first request, start termination procedure. */ @@ -1133,6 +1127,7 @@ namespace ams::kern { /* If the thread is runnable, send a termination interrupt to other cores. */ if (this->GetState() == ThreadState_Runnable) { if (const u64 core_mask = this->affinity_mask.GetAffinityMask() & ~(1ul << GetCurrentCoreId()); core_mask != 0) { + cpu::DataSynchronizationBarrier(); Kernel::GetInterruptManager().SendInterProcessorInterrupt(KInterruptName_ThreadTerminate, core_mask); } }