summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar bunnei2021-11-25 20:46:17 -0800
committerGravatar bunnei2021-12-06 16:39:17 -0800
commitabbea575cfcc9e933fbe8f277a5e9f754deb669d (patch)
tree50cf06afc61acb947ba8959a33c0e60b74951c1e /src
parenthle: kernel: KSynchronizationObject: Fix variable shadowing. (diff)
downloadyuzu-abbea575cfcc9e933fbe8f277a5e9f754deb669d.tar.gz
yuzu-abbea575cfcc9e933fbe8f277a5e9f754deb669d.tar.xz
yuzu-abbea575cfcc9e933fbe8f277a5e9f754deb669d.zip
hle: kernel: Add a flag for indicating that the kernel is currently shutting down.
Diffstat (limited to 'src')
-rw-r--r--src/core/hle/kernel/k_scheduler.cpp10
-rw-r--r--src/core/hle/kernel/k_scheduler_lock.h10
-rw-r--r--src/core/hle/kernel/k_thread.cpp5
-rw-r--r--src/core/hle/kernel/k_thread.h4
-rw-r--r--src/core/hle/kernel/kernel.cpp18
-rw-r--r--src/core/hle/kernel/kernel.h2
6 files changed, 49 insertions, 0 deletions
diff --git a/src/core/hle/kernel/k_scheduler.cpp b/src/core/hle/kernel/k_scheduler.cpp
index 6ddbae52c..5423b187e 100644
--- a/src/core/hle/kernel/k_scheduler.cpp
+++ b/src/core/hle/kernel/k_scheduler.cpp
@@ -376,11 +376,21 @@ void KScheduler::ClearSchedulerUpdateNeeded(KernelCore& kernel) {
376} 376}
377 377
378void KScheduler::DisableScheduling(KernelCore& kernel) { 378void KScheduler::DisableScheduling(KernelCore& kernel) {
379 // If we are shutting down the kernel, none of this is relevant anymore.
380 if (kernel.IsShuttingDown()) {
381 return;
382 }
383
379 ASSERT(GetCurrentThreadPointer(kernel)->GetDisableDispatchCount() >= 0); 384 ASSERT(GetCurrentThreadPointer(kernel)->GetDisableDispatchCount() >= 0);
380 GetCurrentThreadPointer(kernel)->DisableDispatch(); 385 GetCurrentThreadPointer(kernel)->DisableDispatch();
381} 386}
382 387
383void KScheduler::EnableScheduling(KernelCore& kernel, u64 cores_needing_scheduling) { 388void KScheduler::EnableScheduling(KernelCore& kernel, u64 cores_needing_scheduling) {
389 // If we are shutting down the kernel, none of this is relevant anymore.
390 if (kernel.IsShuttingDown()) {
391 return;
392 }
393
384 ASSERT(GetCurrentThreadPointer(kernel)->GetDisableDispatchCount() >= 1); 394 ASSERT(GetCurrentThreadPointer(kernel)->GetDisableDispatchCount() >= 1);
385 395
386 if (GetCurrentThreadPointer(kernel)->GetDisableDispatchCount() > 1) { 396 if (GetCurrentThreadPointer(kernel)->GetDisableDispatchCount() > 1) {
diff --git a/src/core/hle/kernel/k_scheduler_lock.h b/src/core/hle/kernel/k_scheduler_lock.h
index c571f2992..93c47f1b1 100644
--- a/src/core/hle/kernel/k_scheduler_lock.h
+++ b/src/core/hle/kernel/k_scheduler_lock.h
@@ -23,6 +23,11 @@ public:
23 } 23 }
24 24
25 void Lock() { 25 void Lock() {
26 // If we are shutting down the kernel, none of this is relevant anymore.
27 if (kernel.IsShuttingDown()) {
28 return;
29 }
30
26 if (IsLockedByCurrentThread()) { 31 if (IsLockedByCurrentThread()) {
27 // If we already own the lock, we can just increment the count. 32 // If we already own the lock, we can just increment the count.
28 ASSERT(lock_count > 0); 33 ASSERT(lock_count > 0);
@@ -43,6 +48,11 @@ public:
43 } 48 }
44 49
45 void Unlock() { 50 void Unlock() {
51 // If we are shutting down the kernel, none of this is relevant anymore.
52 if (kernel.IsShuttingDown()) {
53 return;
54 }
55
46 ASSERT(IsLockedByCurrentThread()); 56 ASSERT(IsLockedByCurrentThread());
47 ASSERT(lock_count > 0); 57 ASSERT(lock_count > 0);
48 58
diff --git a/src/core/hle/kernel/k_thread.cpp b/src/core/hle/kernel/k_thread.cpp
index 813b92ea4..f69978caf 100644
--- a/src/core/hle/kernel/k_thread.cpp
+++ b/src/core/hle/kernel/k_thread.cpp
@@ -1089,6 +1089,11 @@ s32 GetCurrentCoreId(KernelCore& kernel) {
1089} 1089}
1090 1090
1091KScopedDisableDispatch::~KScopedDisableDispatch() { 1091KScopedDisableDispatch::~KScopedDisableDispatch() {
1092 // If we are shutting down the kernel, none of this is relevant anymore.
1093 if (kernel.IsShuttingDown()) {
1094 return;
1095 }
1096
1092 if (GetCurrentThread(kernel).GetDisableDispatchCount() <= 1) { 1097 if (GetCurrentThread(kernel).GetDisableDispatchCount() <= 1) {
1093 auto scheduler = kernel.CurrentScheduler(); 1098 auto scheduler = kernel.CurrentScheduler();
1094 1099
diff --git a/src/core/hle/kernel/k_thread.h b/src/core/hle/kernel/k_thread.h
index 1cde71e89..be1bc59ae 100644
--- a/src/core/hle/kernel/k_thread.h
+++ b/src/core/hle/kernel/k_thread.h
@@ -794,6 +794,10 @@ public:
794class KScopedDisableDispatch { 794class KScopedDisableDispatch {
795public: 795public:
796 [[nodiscard]] explicit KScopedDisableDispatch(KernelCore& kernel_) : kernel{kernel_} { 796 [[nodiscard]] explicit KScopedDisableDispatch(KernelCore& kernel_) : kernel{kernel_} {
797 // If we are shutting down the kernel, none of this is relevant anymore.
798 if (kernel.IsShuttingDown()) {
799 return;
800 }
797 GetCurrentThread(kernel).DisableDispatch(); 801 GetCurrentThread(kernel).DisableDispatch();
798 } 802 }
799 803
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp
index cf155ff66..1a47d4716 100644
--- a/src/core/hle/kernel/kernel.cpp
+++ b/src/core/hle/kernel/kernel.cpp
@@ -14,6 +14,7 @@
14#include "common/assert.h" 14#include "common/assert.h"
15#include "common/logging/log.h" 15#include "common/logging/log.h"
16#include "common/microprofile.h" 16#include "common/microprofile.h"
17#include "common/scope_exit.h"
17#include "common/thread.h" 18#include "common/thread.h"
18#include "common/thread_worker.h" 19#include "common/thread_worker.h"
19#include "core/arm/arm_interface.h" 20#include "core/arm/arm_interface.h"
@@ -90,6 +91,9 @@ struct KernelCore::Impl {
90 } 91 }
91 92
92 void Shutdown() { 93 void Shutdown() {
94 is_shutting_down.store(true, std::memory_order_relaxed);
95 SCOPE_EXIT({ is_shutting_down.store(false, std::memory_order_relaxed); });
96
93 process_list.clear(); 97 process_list.clear();
94 98
95 // Close all open server ports. 99 // Close all open server ports.
@@ -338,7 +342,16 @@ struct KernelCore::Impl {
338 is_phantom_mode_for_singlecore = value; 342 is_phantom_mode_for_singlecore = value;
339 } 343 }
340 344
345 bool IsShuttingDown() const {
346 return is_shutting_down.load(std::memory_order_relaxed);
347 }
348
341 KThread* GetCurrentEmuThread() { 349 KThread* GetCurrentEmuThread() {
350 // If we are shutting down the kernel, none of this is relevant anymore.
351 if (IsShuttingDown()) {
352 return {};
353 }
354
342 const auto thread_id = GetCurrentHostThreadID(); 355 const auto thread_id = GetCurrentHostThreadID();
343 if (thread_id >= Core::Hardware::NUM_CPU_CORES) { 356 if (thread_id >= Core::Hardware::NUM_CPU_CORES) {
344 return GetHostDummyThread(); 357 return GetHostDummyThread();
@@ -754,6 +767,7 @@ struct KernelCore::Impl {
754 std::vector<std::unique_ptr<KThread>> dummy_threads; 767 std::vector<std::unique_ptr<KThread>> dummy_threads;
755 768
756 bool is_multicore{}; 769 bool is_multicore{};
770 std::atomic_bool is_shutting_down{};
757 bool is_phantom_mode_for_singlecore{}; 771 bool is_phantom_mode_for_singlecore{};
758 u32 single_core_thread_id{}; 772 u32 single_core_thread_id{};
759 773
@@ -1066,6 +1080,10 @@ bool KernelCore::IsMulticore() const {
1066 return impl->is_multicore; 1080 return impl->is_multicore;
1067} 1081}
1068 1082
1083bool KernelCore::IsShuttingDown() const {
1084 return impl->IsShuttingDown();
1085}
1086
1069void KernelCore::ExceptionalExit() { 1087void KernelCore::ExceptionalExit() {
1070 exception_exited = true; 1088 exception_exited = true;
1071 Suspend(true); 1089 Suspend(true);
diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h
index 3499f8b90..eacf9dc61 100644
--- a/src/core/hle/kernel/kernel.h
+++ b/src/core/hle/kernel/kernel.h
@@ -274,6 +274,8 @@ public:
274 274
275 bool IsMulticore() const; 275 bool IsMulticore() const;
276 276
277 bool IsShuttingDown() const;
278
277 void EnterSVCProfile(); 279 void EnterSVCProfile();
278 280
279 void ExitSVCProfile(); 281 void ExitSVCProfile();