diff options
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/cpu_manager.cpp | 51 | ||||
| -rw-r--r-- | src/core/cpu_manager.h | 21 | ||||
| -rw-r--r-- | src/core/hle/kernel/k_scheduler.cpp | 7 | ||||
| -rw-r--r-- | src/core/hle/kernel/k_scheduler.h | 1 | ||||
| -rw-r--r-- | src/core/hle/kernel/k_thread.cpp | 15 | ||||
| -rw-r--r-- | src/core/hle/kernel/k_thread.h | 3 |
6 files changed, 36 insertions, 62 deletions
diff --git a/src/core/cpu_manager.cpp b/src/core/cpu_manager.cpp index fd6928105..f184b904b 100644 --- a/src/core/cpu_manager.cpp +++ b/src/core/cpu_manager.cpp | |||
| @@ -41,51 +41,32 @@ void CpuManager::Shutdown() { | |||
| 41 | } | 41 | } |
| 42 | } | 42 | } |
| 43 | 43 | ||
| 44 | std::function<void(void*)> CpuManager::GetGuestThreadStartFunc() { | 44 | void CpuManager::GuestThreadFunction() { |
| 45 | return GuestThreadFunction; | 45 | if (is_multicore) { |
| 46 | } | 46 | MultiCoreRunGuestThread(); |
| 47 | |||
| 48 | std::function<void(void*)> CpuManager::GetIdleThreadStartFunc() { | ||
| 49 | return IdleThreadFunction; | ||
| 50 | } | ||
| 51 | |||
| 52 | std::function<void(void*)> CpuManager::GetShutdownThreadStartFunc() { | ||
| 53 | return ShutdownThreadFunction; | ||
| 54 | } | ||
| 55 | |||
| 56 | void CpuManager::GuestThreadFunction(void* cpu_manager_) { | ||
| 57 | CpuManager* cpu_manager = static_cast<CpuManager*>(cpu_manager_); | ||
| 58 | if (cpu_manager->is_multicore) { | ||
| 59 | cpu_manager->MultiCoreRunGuestThread(); | ||
| 60 | } else { | 47 | } else { |
| 61 | cpu_manager->SingleCoreRunGuestThread(); | 48 | SingleCoreRunGuestThread(); |
| 62 | } | 49 | } |
| 63 | } | 50 | } |
| 64 | 51 | ||
| 65 | void CpuManager::GuestRewindFunction(void* cpu_manager_) { | 52 | void CpuManager::GuestRewindFunction() { |
| 66 | CpuManager* cpu_manager = static_cast<CpuManager*>(cpu_manager_); | 53 | if (is_multicore) { |
| 67 | if (cpu_manager->is_multicore) { | 54 | MultiCoreRunGuestLoop(); |
| 68 | cpu_manager->MultiCoreRunGuestLoop(); | ||
| 69 | } else { | 55 | } else { |
| 70 | cpu_manager->SingleCoreRunGuestLoop(); | 56 | SingleCoreRunGuestLoop(); |
| 71 | } | 57 | } |
| 72 | } | 58 | } |
| 73 | 59 | ||
| 74 | void CpuManager::IdleThreadFunction(void* cpu_manager_) { | 60 | void CpuManager::IdleThreadFunction() { |
| 75 | CpuManager* cpu_manager = static_cast<CpuManager*>(cpu_manager_); | 61 | if (is_multicore) { |
| 76 | if (cpu_manager->is_multicore) { | 62 | MultiCoreRunIdleThread(); |
| 77 | cpu_manager->MultiCoreRunIdleThread(); | ||
| 78 | } else { | 63 | } else { |
| 79 | cpu_manager->SingleCoreRunIdleThread(); | 64 | SingleCoreRunIdleThread(); |
| 80 | } | 65 | } |
| 81 | } | 66 | } |
| 82 | 67 | ||
| 83 | void CpuManager::ShutdownThreadFunction(void* cpu_manager) { | 68 | void CpuManager::ShutdownThreadFunction() { |
| 84 | static_cast<CpuManager*>(cpu_manager)->ShutdownThread(); | 69 | ShutdownThread(); |
| 85 | } | ||
| 86 | |||
| 87 | void* CpuManager::GetStartFuncParameter() { | ||
| 88 | return this; | ||
| 89 | } | 70 | } |
| 90 | 71 | ||
| 91 | /////////////////////////////////////////////////////////////////////////////// | 72 | /////////////////////////////////////////////////////////////////////////////// |
| @@ -97,7 +78,7 @@ void CpuManager::MultiCoreRunGuestThread() { | |||
| 97 | kernel.CurrentScheduler()->OnThreadStart(); | 78 | kernel.CurrentScheduler()->OnThreadStart(); |
| 98 | auto* thread = kernel.CurrentScheduler()->GetSchedulerCurrentThread(); | 79 | auto* thread = kernel.CurrentScheduler()->GetSchedulerCurrentThread(); |
| 99 | auto& host_context = thread->GetHostContext(); | 80 | auto& host_context = thread->GetHostContext(); |
| 100 | host_context->SetRewindPoint(GuestRewindFunction, this); | 81 | host_context->SetRewindPoint([this] { GuestRewindFunction(); }); |
| 101 | MultiCoreRunGuestLoop(); | 82 | MultiCoreRunGuestLoop(); |
| 102 | } | 83 | } |
| 103 | 84 | ||
| @@ -134,7 +115,7 @@ void CpuManager::SingleCoreRunGuestThread() { | |||
| 134 | kernel.CurrentScheduler()->OnThreadStart(); | 115 | kernel.CurrentScheduler()->OnThreadStart(); |
| 135 | auto* thread = kernel.CurrentScheduler()->GetSchedulerCurrentThread(); | 116 | auto* thread = kernel.CurrentScheduler()->GetSchedulerCurrentThread(); |
| 136 | auto& host_context = thread->GetHostContext(); | 117 | auto& host_context = thread->GetHostContext(); |
| 137 | host_context->SetRewindPoint(GuestRewindFunction, this); | 118 | host_context->SetRewindPoint([this] { GuestRewindFunction(); }); |
| 138 | SingleCoreRunGuestLoop(); | 119 | SingleCoreRunGuestLoop(); |
| 139 | } | 120 | } |
| 140 | 121 | ||
diff --git a/src/core/cpu_manager.h b/src/core/cpu_manager.h index f0751fc58..76dc58ee1 100644 --- a/src/core/cpu_manager.h +++ b/src/core/cpu_manager.h | |||
| @@ -50,10 +50,15 @@ public: | |||
| 50 | void Initialize(); | 50 | void Initialize(); |
| 51 | void Shutdown(); | 51 | void Shutdown(); |
| 52 | 52 | ||
| 53 | static std::function<void(void*)> GetGuestThreadStartFunc(); | 53 | std::function<void()> GetGuestThreadStartFunc() { |
| 54 | static std::function<void(void*)> GetIdleThreadStartFunc(); | 54 | return [this] { GuestThreadFunction(); }; |
| 55 | static std::function<void(void*)> GetShutdownThreadStartFunc(); | 55 | } |
| 56 | void* GetStartFuncParameter(); | 56 | std::function<void()> GetIdleThreadStartFunc() { |
| 57 | return [this] { IdleThreadFunction(); }; | ||
| 58 | } | ||
| 59 | std::function<void()> GetShutdownThreadStartFunc() { | ||
| 60 | return [this] { ShutdownThreadFunction(); }; | ||
| 61 | } | ||
| 57 | 62 | ||
| 58 | void PreemptSingleCore(bool from_running_enviroment = true); | 63 | void PreemptSingleCore(bool from_running_enviroment = true); |
| 59 | 64 | ||
| @@ -62,10 +67,10 @@ public: | |||
| 62 | } | 67 | } |
| 63 | 68 | ||
| 64 | private: | 69 | private: |
| 65 | static void GuestThreadFunction(void* cpu_manager); | 70 | void GuestThreadFunction(); |
| 66 | static void GuestRewindFunction(void* cpu_manager); | 71 | void GuestRewindFunction(); |
| 67 | static void IdleThreadFunction(void* cpu_manager); | 72 | void IdleThreadFunction(); |
| 68 | static void ShutdownThreadFunction(void* cpu_manager); | 73 | void ShutdownThreadFunction(); |
| 69 | 74 | ||
| 70 | void MultiCoreRunGuestThread(); | 75 | void MultiCoreRunGuestThread(); |
| 71 | void MultiCoreRunGuestLoop(); | 76 | void MultiCoreRunGuestLoop(); |
diff --git a/src/core/hle/kernel/k_scheduler.cpp b/src/core/hle/kernel/k_scheduler.cpp index d586b3f5c..d599d2bcb 100644 --- a/src/core/hle/kernel/k_scheduler.cpp +++ b/src/core/hle/kernel/k_scheduler.cpp | |||
| @@ -622,7 +622,7 @@ void KScheduler::YieldToAnyThread(KernelCore& kernel) { | |||
| 622 | } | 622 | } |
| 623 | 623 | ||
| 624 | KScheduler::KScheduler(Core::System& system_, s32 core_id_) : system{system_}, core_id{core_id_} { | 624 | KScheduler::KScheduler(Core::System& system_, s32 core_id_) : system{system_}, core_id{core_id_} { |
| 625 | switch_fiber = std::make_shared<Common::Fiber>(OnSwitch, this); | 625 | switch_fiber = std::make_shared<Common::Fiber>([this] { SwitchToCurrent(); }); |
| 626 | state.needs_scheduling.store(true); | 626 | state.needs_scheduling.store(true); |
| 627 | state.interrupt_task_thread_runnable = false; | 627 | state.interrupt_task_thread_runnable = false; |
| 628 | state.should_count_idle = false; | 628 | state.should_count_idle = false; |
| @@ -778,11 +778,6 @@ void KScheduler::ScheduleImpl() { | |||
| 778 | next_scheduler.SwitchContextStep2(); | 778 | next_scheduler.SwitchContextStep2(); |
| 779 | } | 779 | } |
| 780 | 780 | ||
| 781 | void KScheduler::OnSwitch(void* this_scheduler) { | ||
| 782 | KScheduler* sched = static_cast<KScheduler*>(this_scheduler); | ||
| 783 | sched->SwitchToCurrent(); | ||
| 784 | } | ||
| 785 | |||
| 786 | void KScheduler::SwitchToCurrent() { | 781 | void KScheduler::SwitchToCurrent() { |
| 787 | while (true) { | 782 | while (true) { |
| 788 | { | 783 | { |
diff --git a/src/core/hle/kernel/k_scheduler.h b/src/core/hle/kernel/k_scheduler.h index 3f90656ee..bd66bffc4 100644 --- a/src/core/hle/kernel/k_scheduler.h +++ b/src/core/hle/kernel/k_scheduler.h | |||
| @@ -165,7 +165,6 @@ private: | |||
| 165 | */ | 165 | */ |
| 166 | void UpdateLastContextSwitchTime(KThread* thread, KProcess* process); | 166 | void UpdateLastContextSwitchTime(KThread* thread, KProcess* process); |
| 167 | 167 | ||
| 168 | static void OnSwitch(void* this_scheduler); | ||
| 169 | void SwitchToCurrent(); | 168 | void SwitchToCurrent(); |
| 170 | 169 | ||
| 171 | KThread* prev_thread{}; | 170 | KThread* prev_thread{}; |
diff --git a/src/core/hle/kernel/k_thread.cpp b/src/core/hle/kernel/k_thread.cpp index 8d7faa662..23bf7425a 100644 --- a/src/core/hle/kernel/k_thread.cpp +++ b/src/core/hle/kernel/k_thread.cpp | |||
| @@ -246,14 +246,12 @@ Result KThread::Initialize(KThreadFunction func, uintptr_t arg, VAddr user_stack | |||
| 246 | 246 | ||
| 247 | Result KThread::InitializeThread(KThread* thread, KThreadFunction func, uintptr_t arg, | 247 | Result KThread::InitializeThread(KThread* thread, KThreadFunction func, uintptr_t arg, |
| 248 | VAddr user_stack_top, s32 prio, s32 core, KProcess* owner, | 248 | VAddr user_stack_top, s32 prio, s32 core, KProcess* owner, |
| 249 | ThreadType type, std::function<void(void*)>&& init_func, | 249 | ThreadType type, std::function<void()>&& init_func) { |
| 250 | void* init_func_parameter) { | ||
| 251 | // Initialize the thread. | 250 | // Initialize the thread. |
| 252 | R_TRY(thread->Initialize(func, arg, user_stack_top, prio, core, owner, type)); | 251 | R_TRY(thread->Initialize(func, arg, user_stack_top, prio, core, owner, type)); |
| 253 | 252 | ||
| 254 | // Initialize emulation parameters. | 253 | // Initialize emulation parameters. |
| 255 | thread->host_context = | 254 | thread->host_context = std::make_shared<Common::Fiber>(std::move(init_func)); |
| 256 | std::make_shared<Common::Fiber>(std::move(init_func), init_func_parameter); | ||
| 257 | thread->is_single_core = !Settings::values.use_multi_core.GetValue(); | 255 | thread->is_single_core = !Settings::values.use_multi_core.GetValue(); |
| 258 | 256 | ||
| 259 | return ResultSuccess; | 257 | return ResultSuccess; |
| @@ -265,15 +263,13 @@ Result KThread::InitializeDummyThread(KThread* thread) { | |||
| 265 | 263 | ||
| 266 | Result KThread::InitializeIdleThread(Core::System& system, KThread* thread, s32 virt_core) { | 264 | Result KThread::InitializeIdleThread(Core::System& system, KThread* thread, s32 virt_core) { |
| 267 | return InitializeThread(thread, {}, {}, {}, IdleThreadPriority, virt_core, {}, ThreadType::Main, | 265 | return InitializeThread(thread, {}, {}, {}, IdleThreadPriority, virt_core, {}, ThreadType::Main, |
| 268 | Core::CpuManager::GetIdleThreadStartFunc(), | 266 | system.GetCpuManager().GetIdleThreadStartFunc()); |
| 269 | system.GetCpuManager().GetStartFuncParameter()); | ||
| 270 | } | 267 | } |
| 271 | 268 | ||
| 272 | Result KThread::InitializeHighPriorityThread(Core::System& system, KThread* thread, | 269 | Result KThread::InitializeHighPriorityThread(Core::System& system, KThread* thread, |
| 273 | KThreadFunction func, uintptr_t arg, s32 virt_core) { | 270 | KThreadFunction func, uintptr_t arg, s32 virt_core) { |
| 274 | return InitializeThread(thread, func, arg, {}, {}, virt_core, nullptr, ThreadType::HighPriority, | 271 | return InitializeThread(thread, func, arg, {}, {}, virt_core, nullptr, ThreadType::HighPriority, |
| 275 | Core::CpuManager::GetShutdownThreadStartFunc(), | 272 | system.GetCpuManager().GetShutdownThreadStartFunc()); |
| 276 | system.GetCpuManager().GetStartFuncParameter()); | ||
| 277 | } | 273 | } |
| 278 | 274 | ||
| 279 | Result KThread::InitializeUserThread(Core::System& system, KThread* thread, KThreadFunction func, | 275 | Result KThread::InitializeUserThread(Core::System& system, KThread* thread, KThreadFunction func, |
| @@ -281,8 +277,7 @@ Result KThread::InitializeUserThread(Core::System& system, KThread* thread, KThr | |||
| 281 | KProcess* owner) { | 277 | KProcess* owner) { |
| 282 | system.Kernel().GlobalSchedulerContext().AddThread(thread); | 278 | system.Kernel().GlobalSchedulerContext().AddThread(thread); |
| 283 | return InitializeThread(thread, func, arg, user_stack_top, prio, virt_core, owner, | 279 | return InitializeThread(thread, func, arg, user_stack_top, prio, virt_core, owner, |
| 284 | ThreadType::User, Core::CpuManager::GetGuestThreadStartFunc(), | 280 | ThreadType::User, system.GetCpuManager().GetGuestThreadStartFunc()); |
| 285 | system.GetCpuManager().GetStartFuncParameter()); | ||
| 286 | } | 281 | } |
| 287 | 282 | ||
| 288 | void KThread::PostDestroy(uintptr_t arg) { | 283 | void KThread::PostDestroy(uintptr_t arg) { |
diff --git a/src/core/hle/kernel/k_thread.h b/src/core/hle/kernel/k_thread.h index 94c4cd1c8..28cd7ecb0 100644 --- a/src/core/hle/kernel/k_thread.h +++ b/src/core/hle/kernel/k_thread.h | |||
| @@ -729,8 +729,7 @@ private: | |||
| 729 | [[nodiscard]] static Result InitializeThread(KThread* thread, KThreadFunction func, | 729 | [[nodiscard]] static Result InitializeThread(KThread* thread, KThreadFunction func, |
| 730 | uintptr_t arg, VAddr user_stack_top, s32 prio, | 730 | uintptr_t arg, VAddr user_stack_top, s32 prio, |
| 731 | s32 core, KProcess* owner, ThreadType type, | 731 | s32 core, KProcess* owner, ThreadType type, |
| 732 | std::function<void(void*)>&& init_func, | 732 | std::function<void()>&& init_func); |
| 733 | void* init_func_parameter); | ||
| 734 | 733 | ||
| 735 | static void RestorePriority(KernelCore& kernel_ctx, KThread* thread); | 734 | static void RestorePriority(KernelCore& kernel_ctx, KThread* thread); |
| 736 | 735 | ||