diff options
author | bunnei <bunneidev@gmail.com> | 2021-08-07 08:04:32 +0200 |
---|---|---|
committer | bunnei <bunneidev@gmail.com> | 2021-12-07 01:39:16 +0100 |
commit | 04daefa4887fac9f90d873b5ae4b87548eafb2f0 (patch) | |
tree | 47ff9a164b0bc0cfbb7b7104100f7cd5f7931322 /src/core | |
parent | core: hle: kernel: Ensure idle threads are closed before destroying scheduler. (diff) | |
download | yuzu-04daefa4887fac9f90d873b5ae4b87548eafb2f0.tar yuzu-04daefa4887fac9f90d873b5ae4b87548eafb2f0.tar.gz yuzu-04daefa4887fac9f90d873b5ae4b87548eafb2f0.tar.bz2 yuzu-04daefa4887fac9f90d873b5ae4b87548eafb2f0.tar.lz yuzu-04daefa4887fac9f90d873b5ae4b87548eafb2f0.tar.xz yuzu-04daefa4887fac9f90d873b5ae4b87548eafb2f0.tar.zst yuzu-04daefa4887fac9f90d873b5ae4b87548eafb2f0.zip |
Diffstat (limited to 'src/core')
-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 // Setup the stack parameters. StackParameters& sp = GetStackParameters(); sp.cur_thread = this; - sp.disable_count = 1; + sp.disable_count = 0; SetInExceptionHandler(); // Set thread ID. @@ -966,6 +966,9 @@ ResultCode KThread::Run() { // Set our state and finish. SetState(ThreadState::Runnable); + + DisableDispatch(); + return ResultSuccess; } } @@ -1050,4 +1053,16 @@ s32 GetCurrentCoreId(KernelCore& kernel) { return GetCurrentThread(kernel).GetCurrentCore(); } +KScopedDisableDispatch::~KScopedDisableDispatch() { + if (GetCurrentThread(kernel).GetDisableDispatchCount() <= 1) { + auto scheduler = kernel.CurrentScheduler(); + + if (scheduler) { + scheduler->RescheduleCurrentCore(); + } + } else { + GetCurrentThread(kernel).EnableDispatch(); + } +} + } // 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: sleeping_queue = q; } + [[nodiscard]] bool IsKernelThread() const { + return GetActiveCore() == 3; + } + [[nodiscard]] s32 GetDisableDispatchCount() const { + if (IsKernelThread()) { + // TODO(bunnei): Until kernel threads are emulated, we cannot enable/disable dispatch. + return 1; + } + return this->GetStackParameters().disable_count; } void DisableDispatch() { + if (IsKernelThread()) { + // TODO(bunnei): Until kernel threads are emulated, we cannot enable/disable dispatch. + return; + } + ASSERT(GetCurrentThread(kernel).GetDisableDispatchCount() >= 0); this->GetStackParameters().disable_count++; } void EnableDispatch() { + if (IsKernelThread()) { + // TODO(bunnei): Until kernel threads are emulated, we cannot enable/disable dispatch. + return; + } + ASSERT(GetCurrentThread(kernel).GetDisableDispatchCount() > 0); this->GetStackParameters().disable_count--; } @@ -752,4 +771,16 @@ public: } }; +class KScopedDisableDispatch { +public: + explicit KScopedDisableDispatch(KernelCore& kernel_) : kernel{kernel_} { + GetCurrentThread(kernel).DisableDispatch(); + } + + ~KScopedDisableDispatch(); + +private: + KernelCore& kernel; +}; + } // namespace Kernel |