From 276ca88c9e854f461823d873a4673d15a11773f3 Mon Sep 17 00:00:00 2001 From: Weiyi Wang Date: Fri, 1 Feb 2019 11:23:39 -0500 Subject: [PATCH] kernel/thread: replace usage of Core::CPU() --- src/core/core.cpp | 2 ++ src/core/hle/kernel/thread.cpp | 8 ++++---- src/core/hle/kernel/thread.h | 9 +++++++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/core/core.cpp b/src/core/core.cpp index 671363169..f44836236 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -187,6 +187,8 @@ System::ResultStatus System::Init(EmuWindow& emu_window, u32 system_mode) { cpu_core = std::make_unique(*this, USER32MODE); } + kernel->GetThreadManager().SetCPU(*cpu_core); + if (Settings::values.enable_dsp_lle) { dsp_core = std::make_unique(*memory, Settings::values.enable_dsp_lle_multithread); diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index 4f4c9b174..994beef4e 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp @@ -38,7 +38,7 @@ u32 ThreadManager::NewThreadId() { } Thread::Thread(KernelSystem& kernel) - : WaitObject(kernel), context(Core::CPU().NewContext()), + : WaitObject(kernel), context(kernel.GetThreadManager().NewContext()), thread_manager(kernel.GetThreadManager()) {} Thread::~Thread() {} @@ -86,7 +86,7 @@ void ThreadManager::SwitchContext(Thread* new_thread) { // Save context for previous thread if (previous_thread) { previous_thread->last_running_ticks = timing.GetTicks(); - Core::CPU().SaveContext(previous_thread->context); + cpu->SaveContext(previous_thread->context); if (previous_thread->status == ThreadStatus::Running) { // This is only the case when a reschedule is triggered without the current thread @@ -117,8 +117,8 @@ void ThreadManager::SwitchContext(Thread* new_thread) { ¤t_thread->owner_process->vm_manager.page_table); } - Core::CPU().LoadContext(new_thread->context); - Core::CPU().SetCP15Register(CP15_THREAD_URO, new_thread->GetTLSAddress()); + cpu->LoadContext(new_thread->context); + cpu->SetCP15Register(CP15_THREAD_URO, new_thread->GetTLSAddress()); } else { current_thread = nullptr; // Note: We do not reset the current process and current page table when idling because diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h index e0af473e0..8f5da92c7 100644 --- a/src/core/hle/kernel/thread.h +++ b/src/core/hle/kernel/thread.h @@ -101,6 +101,14 @@ public: */ const std::vector>& GetThreadList(); + void SetCPU(ARM_Interface& cpu) { + this->cpu = &cpu; + } + + std::unique_ptr NewContext() { + return cpu->NewContext(); + } + private: /** * Switches the CPU's active thread context to that of the specified thread @@ -122,6 +130,7 @@ private: void ThreadWakeupCallback(u64 thread_id, s64 cycles_late); Kernel::KernelSystem& kernel; + ARM_Interface* cpu; u32 next_thread_id = 1; SharedPtr current_thread;