From 24d7aaf43c6b243f7123401545527ed7a25a3f26 Mon Sep 17 00:00:00 2001 From: Liam Date: Sat, 18 Jun 2022 16:54:33 -0400 Subject: kernel: wait for threads to stop on pause --- src/core/hle/kernel/k_thread.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/core/hle/kernel/k_thread.cpp') diff --git a/src/core/hle/kernel/k_thread.cpp b/src/core/hle/kernel/k_thread.cpp index 8d48a7901..b8aed18b1 100644 --- a/src/core/hle/kernel/k_thread.cpp +++ b/src/core/hle/kernel/k_thread.cpp @@ -748,6 +748,19 @@ void KThread::Continue() { KScheduler::OnThreadStateChanged(kernel, this, old_state); } +void KThread::WaitUntilSuspended() { + // Make sure we have a suspend requested. + ASSERT(IsSuspendRequested()); + + // Loop until the thread is not executing on any core. + for (std::size_t i = 0; i < static_cast(Core::Hardware::NUM_CPU_CORES); ++i) { + KThread* core_thread{}; + do { + core_thread = kernel.Scheduler(i).GetCurrentThread(); + } while (core_thread == this); + } +} + ResultCode KThread::SetActivity(Svc::ThreadActivity activity) { // Lock ourselves. KScopedLightLock lk(activity_pause_lock); -- cgit v1.2.3