diff options
| author | 2021-08-06 23:04:32 -0700 | |
|---|---|---|
| committer | 2021-12-06 16:39:16 -0800 | |
| commit | 04daefa4887fac9f90d873b5ae4b87548eafb2f0 (patch) | |
| tree | 47ff9a164b0bc0cfbb7b7104100f7cd5f7931322 /src | |
| parent | core: hle: kernel: Ensure idle threads are closed before destroying scheduler. (diff) | |
| download | yuzu-04daefa4887fac9f90d873b5ae4b87548eafb2f0.tar.gz yuzu-04daefa4887fac9f90d873b5ae4b87548eafb2f0.tar.xz yuzu-04daefa4887fac9f90d873b5ae4b87548eafb2f0.zip | |
core: hle: kernel: k_thread: Add KScopedDisableDispatch.
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/hle/kernel/k_thread.cpp | 17 | ||||
| -rw-r--r-- | src/core/hle/kernel/k_thread.h | 31 |
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 db65ce79a..de94c737d 100644 --- a/src/core/hle/kernel/k_thread.cpp +++ b/src/core/hle/kernel/k_thread.cpp | |||
| @@ -184,7 +184,7 @@ ResultCode KThread::Initialize(KThreadFunction func, uintptr_t arg, VAddr user_s | |||
| 184 | // Setup the stack parameters. | 184 | // Setup the stack parameters. |
| 185 | StackParameters& sp = GetStackParameters(); | 185 | StackParameters& sp = GetStackParameters(); |
| 186 | sp.cur_thread = this; | 186 | sp.cur_thread = this; |
| 187 | sp.disable_count = 1; | 187 | sp.disable_count = 0; |
| 188 | SetInExceptionHandler(); | 188 | SetInExceptionHandler(); |
| 189 | 189 | ||
| 190 | // Set thread ID. | 190 | // Set thread ID. |
| @@ -966,6 +966,9 @@ ResultCode KThread::Run() { | |||
| 966 | 966 | ||
| 967 | // Set our state and finish. | 967 | // Set our state and finish. |
| 968 | SetState(ThreadState::Runnable); | 968 | SetState(ThreadState::Runnable); |
| 969 | |||
| 970 | DisableDispatch(); | ||
| 971 | |||
| 969 | return ResultSuccess; | 972 | return ResultSuccess; |
| 970 | } | 973 | } |
| 971 | } | 974 | } |
| @@ -1050,4 +1053,16 @@ s32 GetCurrentCoreId(KernelCore& kernel) { | |||
| 1050 | return GetCurrentThread(kernel).GetCurrentCore(); | 1053 | return GetCurrentThread(kernel).GetCurrentCore(); |
| 1051 | } | 1054 | } |
| 1052 | 1055 | ||
| 1056 | KScopedDisableDispatch::~KScopedDisableDispatch() { | ||
| 1057 | if (GetCurrentThread(kernel).GetDisableDispatchCount() <= 1) { | ||
| 1058 | auto scheduler = kernel.CurrentScheduler(); | ||
| 1059 | |||
| 1060 | if (scheduler) { | ||
| 1061 | scheduler->RescheduleCurrentCore(); | ||
| 1062 | } | ||
| 1063 | } else { | ||
| 1064 | GetCurrentThread(kernel).EnableDispatch(); | ||
| 1065 | } | ||
| 1066 | } | ||
| 1067 | |||
| 1053 | } // namespace Kernel | 1068 | } // 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 | ||
| 774 | class KScopedDisableDispatch { | ||
| 775 | public: | ||
| 776 | explicit KScopedDisableDispatch(KernelCore& kernel_) : kernel{kernel_} { | ||
| 777 | GetCurrentThread(kernel).DisableDispatch(); | ||
| 778 | } | ||
| 779 | |||
| 780 | ~KScopedDisableDispatch(); | ||
| 781 | |||
| 782 | private: | ||
| 783 | KernelCore& kernel; | ||
| 784 | }; | ||
| 785 | |||
| 755 | } // namespace Kernel | 786 | } // namespace Kernel |