summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2022-06-22 23:46:33 +0200
committerGitHub <noreply@github.com>2022-06-22 23:46:33 +0200
commit9da4e62573cdaa8a48dd18068642b494cfed9a04 (patch)
treec179c5fa993f3e840d6e0051ae28ad04520e2723 /src
parentMerge pull request #8455 from lat9nq/mingw-clang (diff)
parentkernel: wait for threads to stop on pause (diff)
downloadyuzu-9da4e62573cdaa8a48dd18068642b494cfed9a04.tar
yuzu-9da4e62573cdaa8a48dd18068642b494cfed9a04.tar.gz
yuzu-9da4e62573cdaa8a48dd18068642b494cfed9a04.tar.bz2
yuzu-9da4e62573cdaa8a48dd18068642b494cfed9a04.tar.lz
yuzu-9da4e62573cdaa8a48dd18068642b494cfed9a04.tar.xz
yuzu-9da4e62573cdaa8a48dd18068642b494cfed9a04.tar.zst
yuzu-9da4e62573cdaa8a48dd18068642b494cfed9a04.zip
Diffstat (limited to 'src')
-rw-r--r--src/core/hle/kernel/k_thread.cpp13
-rw-r--r--src/core/hle/kernel/k_thread.h2
-rw-r--r--src/core/hle/kernel/kernel.cpp7
3 files changed, 22 insertions, 0 deletions
diff --git a/src/core/hle/kernel/k_thread.cpp b/src/core/hle/kernel/k_thread.cpp
index 268789150..c0a091bb6 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<std::size_t>(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);
diff --git a/src/core/hle/kernel/k_thread.h b/src/core/hle/kernel/k_thread.h
index f4d83f99a..8c1f8a344 100644
--- a/src/core/hle/kernel/k_thread.h
+++ b/src/core/hle/kernel/k_thread.h
@@ -207,6 +207,8 @@ public:
void Continue();
+ void WaitUntilSuspended();
+
constexpr void SetSyncedIndex(s32 index) {
synced_index = index;
}
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp
index 66c8f4455..94953e257 100644
--- a/src/core/hle/kernel/kernel.cpp
+++ b/src/core/hle/kernel/kernel.cpp
@@ -1078,6 +1078,13 @@ void KernelCore::Suspend(bool suspended) {
for (auto* process : GetProcessList()) {
process->SetActivity(activity);
+
+ if (should_suspend) {
+ // Wait for execution to stop
+ for (auto* thread : process->GetThreadList()) {
+ thread->WaitUntilSuspended();
+ }
+ }
}
}