diff options
author | Fernando Sahmkow <fsahmkow27@gmail.com> | 2020-03-10 16:50:33 +0100 |
---|---|---|
committer | Fernando Sahmkow <fsahmkow27@gmail.com> | 2020-06-27 17:35:43 +0200 |
commit | a439cdf22ea50f0e39cb51f6dff15fee3b495d16 (patch) | |
tree | 2c88310d7cca08ef451107d9ae6bd5191e7d72e5 /src/core/hle | |
parent | Synchronization: Correct wide Assertion. (diff) | |
download | yuzu-a439cdf22ea50f0e39cb51f6dff15fee3b495d16.tar yuzu-a439cdf22ea50f0e39cb51f6dff15fee3b495d16.tar.gz yuzu-a439cdf22ea50f0e39cb51f6dff15fee3b495d16.tar.bz2 yuzu-a439cdf22ea50f0e39cb51f6dff15fee3b495d16.tar.lz yuzu-a439cdf22ea50f0e39cb51f6dff15fee3b495d16.tar.xz yuzu-a439cdf22ea50f0e39cb51f6dff15fee3b495d16.tar.zst yuzu-a439cdf22ea50f0e39cb51f6dff15fee3b495d16.zip |
Diffstat (limited to 'src/core/hle')
-rw-r--r-- | src/core/hle/kernel/scheduler.cpp | 42 | ||||
-rw-r--r-- | src/core/hle/kernel/scheduler.h | 10 |
2 files changed, 52 insertions, 0 deletions
diff --git a/src/core/hle/kernel/scheduler.cpp b/src/core/hle/kernel/scheduler.cpp index d68d86cdf..00322d997 100644 --- a/src/core/hle/kernel/scheduler.cpp +++ b/src/core/hle/kernel/scheduler.cpp @@ -602,6 +602,48 @@ void Scheduler::OnThreadStart() { SwitchContextStep2(); } +void Scheduler::Unload() { + Thread* thread = current_thread.get(); + if (thread) { + thread->last_running_ticks = system.CoreTiming().GetCPUTicks(); + thread->SetIsRunning(false); + if (!thread->IsHLEThread()) { + auto& cpu_core = system.ArmInterface(core_id); + cpu_core.SaveContext(thread->GetContext32()); + cpu_core.SaveContext(thread->GetContext64()); + // Save the TPIDR_EL0 system register in case it was modified. + thread->SetTPIDR_EL0(cpu_core.GetTPIDR_EL0()); + cpu_core.ClearExclusiveState(); + } + thread->context_guard.unlock(); + } +} + +void Scheduler::Reload() { + Thread* thread = current_thread.get(); + if (thread) { + ASSERT_MSG(thread->GetSchedulingStatus() == ThreadSchedStatus::Runnable, + "Thread must be runnable."); + + // Cancel any outstanding wakeup events for this thread + thread->SetIsRunning(true); + thread->last_running_ticks = system.CoreTiming().GetCPUTicks(); + + auto* const thread_owner_process = thread->GetOwnerProcess(); + if (thread_owner_process != nullptr) { + system.Kernel().MakeCurrentProcess(thread_owner_process); + } + if (!thread->IsHLEThread()) { + auto& cpu_core = system.ArmInterface(core_id); + cpu_core.LoadContext(thread->GetContext32()); + cpu_core.LoadContext(thread->GetContext64()); + cpu_core.SetTlsAddress(thread->GetTLSAddress()); + cpu_core.SetTPIDR_EL0(thread->GetTPIDR_EL0()); + cpu_core.ClearExclusiveState(); + } + } +} + void Scheduler::SwitchContextStep2() { Thread* previous_thread = current_thread_prev.get(); Thread* new_thread = selected_thread.get(); diff --git a/src/core/hle/kernel/scheduler.h b/src/core/hle/kernel/scheduler.h index 5e062bf59..f63cc5085 100644 --- a/src/core/hle/kernel/scheduler.h +++ b/src/core/hle/kernel/scheduler.h @@ -210,6 +210,12 @@ public: /// Reschedules to the next available thread (call after current thread is suspended) void TryDoContextSwitch(); + /// The next two are for SingleCore Only. + /// Unload current thread before preempting core. + void Unload(); + /// Reload current thread after core preemption. + void Reload(); + /// Gets the current running thread Thread* GetCurrentThread() const; @@ -230,6 +236,10 @@ public: void OnThreadStart(); + std::shared_ptr<Common::Fiber> ControlContext() { + return switch_fiber; + } + private: friend class GlobalScheduler; |