summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar bunnei2021-08-06 23:04:32 -0700
committerGravatar bunnei2021-08-07 12:18:47 -0700
commit01af2f4162308029e53143f0caa953bc4c59de92 (patch)
tree44915af7833f785238411725bbc3947b31200ab8 /src
parentcore: hle: kernel: Ensure idle threads are closed before destroying scheduler. (diff)
downloadyuzu-01af2f4162308029e53143f0caa953bc4c59de92.tar.gz
yuzu-01af2f4162308029e53143f0caa953bc4c59de92.tar.xz
yuzu-01af2f4162308029e53143f0caa953bc4c59de92.zip
core: hle: kernel: k_thread: Add KScopedDisableDispatch.
Diffstat (limited to 'src')
-rw-r--r--src/core/hle/kernel/k_thread.cpp17
-rw-r--r--src/core/hle/kernel/k_thread.h31
2 files changed, 47 insertions, 1 deletions
diff --git a/src/core/hle/kernel/k_thread.cpp b/src/core/hle/kernel/k_thread.cpp
index 9f1d3156b..89653e0cb 100644
--- a/src/core/hle/kernel/k_thread.cpp
+++ b/src/core/hle/kernel/k_thread.cpp
@@ -188,7 +188,7 @@ ResultCode KThread::Initialize(KThreadFunction func, uintptr_t arg, VAddr user_s
188 // Setup the stack parameters. 188 // Setup the stack parameters.
189 StackParameters& sp = GetStackParameters(); 189 StackParameters& sp = GetStackParameters();
190 sp.cur_thread = this; 190 sp.cur_thread = this;
191 sp.disable_count = 1; 191 sp.disable_count = 0;
192 SetInExceptionHandler(); 192 SetInExceptionHandler();
193 193
194 // Set thread ID. 194 // Set thread ID.
@@ -970,6 +970,9 @@ ResultCode KThread::Run() {
970 970
971 // Set our state and finish. 971 // Set our state and finish.
972 SetState(ThreadState::Runnable); 972 SetState(ThreadState::Runnable);
973
974 DisableDispatch();
975
973 return ResultSuccess; 976 return ResultSuccess;
974 } 977 }
975} 978}
@@ -1054,4 +1057,16 @@ s32 GetCurrentCoreId(KernelCore& kernel) {
1054 return GetCurrentThread(kernel).GetCurrentCore(); 1057 return GetCurrentThread(kernel).GetCurrentCore();
1055} 1058}
1056 1059
1060KScopedDisableDispatch::~KScopedDisableDispatch() {
1061 if (GetCurrentThread(kernel).GetDisableDispatchCount() <= 1) {
1062 auto scheduler = kernel.CurrentScheduler();
1063
1064 if (scheduler) {
1065 scheduler->RescheduleCurrentCore();
1066 }
1067 } else {
1068 GetCurrentThread(kernel).EnableDispatch();
1069 }
1070}
1071
1057} // namespace Kernel 1072} // namespace Kernel
diff --git a/src/core/hle/kernel/k_thread.h b/src/core/hle/kernel/k_thread.h
index c77f44ad4..a149744c8 100644
--- a/src/core/hle/kernel/k_thread.h
+++ b/src/core/hle/kernel/k_thread.h
@@ -450,16 +450,35 @@ public:
450 sleeping_queue = q; 450 sleeping_queue = q;
451 } 451 }
452 452
453 [[nodiscard]] bool IsKernelThread() const {
454 return GetActiveCore() == 3;
455 }
456
453 [[nodiscard]] s32 GetDisableDispatchCount() const { 457 [[nodiscard]] s32 GetDisableDispatchCount() const {
458 if (IsKernelThread()) {
459 // TODO(bunnei): Until kernel threads are emulated, we cannot enable/disable dispatch.
460 return 1;
461 }
462
454 return this->GetStackParameters().disable_count; 463 return this->GetStackParameters().disable_count;
455 } 464 }
456 465
457 void DisableDispatch() { 466 void DisableDispatch() {
467 if (IsKernelThread()) {
468 // TODO(bunnei): Until kernel threads are emulated, we cannot enable/disable dispatch.
469 return;
470 }
471
458 ASSERT(GetCurrentThread(kernel).GetDisableDispatchCount() >= 0); 472 ASSERT(GetCurrentThread(kernel).GetDisableDispatchCount() >= 0);
459 this->GetStackParameters().disable_count++; 473 this->GetStackParameters().disable_count++;
460 } 474 }
461 475
462 void EnableDispatch() { 476 void EnableDispatch() {
477 if (IsKernelThread()) {
478 // TODO(bunnei): Until kernel threads are emulated, we cannot enable/disable dispatch.
479 return;
480 }
481
463 ASSERT(GetCurrentThread(kernel).GetDisableDispatchCount() > 0); 482 ASSERT(GetCurrentThread(kernel).GetDisableDispatchCount() > 0);
464 this->GetStackParameters().disable_count--; 483 this->GetStackParameters().disable_count--;
465 } 484 }
@@ -752,4 +771,16 @@ public:
752 } 771 }
753}; 772};
754 773
774class KScopedDisableDispatch {
775public:
776 explicit KScopedDisableDispatch(KernelCore& kernel_) : kernel{kernel_} {
777 GetCurrentThread(kernel).DisableDispatch();
778 }
779
780 ~KScopedDisableDispatch();
781
782private:
783 KernelCore& kernel;
784};
785
755} // namespace Kernel 786} // namespace Kernel