diff options
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/cpu_manager.cpp | 11 | ||||
| -rw-r--r-- | src/core/cpu_manager.h | 2 | ||||
| -rw-r--r-- | src/core/hle/kernel/k_scheduler.cpp | 18 | ||||
| -rw-r--r-- | src/core/hle/kernel/k_scheduler.h | 10 | ||||
| -rw-r--r-- | src/core/hle/kernel/k_thread.cpp | 6 | ||||
| -rw-r--r-- | src/core/hle/kernel/k_thread.h | 10 | ||||
| -rw-r--r-- | src/core/hle/kernel/svc.cpp | 3 |
7 files changed, 31 insertions, 29 deletions
diff --git a/src/core/cpu_manager.cpp b/src/core/cpu_manager.cpp index 8f04fb8f5..c35438c6f 100644 --- a/src/core/cpu_manager.cpp +++ b/src/core/cpu_manager.cpp | |||
| @@ -111,7 +111,7 @@ void CpuManager::MultiCoreRunGuestThread() { | |||
| 111 | auto& kernel = system.Kernel(); | 111 | auto& kernel = system.Kernel(); |
| 112 | kernel.CurrentScheduler()->OnThreadStart(); | 112 | kernel.CurrentScheduler()->OnThreadStart(); |
| 113 | auto* thread = kernel.CurrentScheduler()->GetCurrentThread(); | 113 | auto* thread = kernel.CurrentScheduler()->GetCurrentThread(); |
| 114 | auto& host_context = thread->GetHostContext(); | 114 | auto host_context = thread->GetHostContext(); |
| 115 | host_context->SetRewindPoint(GuestRewindFunction, this); | 115 | host_context->SetRewindPoint(GuestRewindFunction, this); |
| 116 | MultiCoreRunGuestLoop(); | 116 | MultiCoreRunGuestLoop(); |
| 117 | } | 117 | } |
| @@ -148,7 +148,8 @@ void CpuManager::MultiCoreRunSuspendThread() { | |||
| 148 | auto core = kernel.GetCurrentHostThreadID(); | 148 | auto core = kernel.GetCurrentHostThreadID(); |
| 149 | auto& scheduler = *kernel.CurrentScheduler(); | 149 | auto& scheduler = *kernel.CurrentScheduler(); |
| 150 | Kernel::KThread* current_thread = scheduler.GetCurrentThread(); | 150 | Kernel::KThread* current_thread = scheduler.GetCurrentThread(); |
| 151 | Common::Fiber::YieldTo(current_thread->GetHostContext(), core_data[core].host_context); | 151 | Common::Fiber::YieldTo(current_thread->GetHostContext(), |
| 152 | core_data[core].host_context.get()); | ||
| 152 | ASSERT(scheduler.ContextSwitchPending()); | 153 | ASSERT(scheduler.ContextSwitchPending()); |
| 153 | ASSERT(core == kernel.GetCurrentHostThreadID()); | 154 | ASSERT(core == kernel.GetCurrentHostThreadID()); |
| 154 | scheduler.RescheduleCurrentCore(); | 155 | scheduler.RescheduleCurrentCore(); |
| @@ -201,7 +202,7 @@ void CpuManager::SingleCoreRunGuestThread() { | |||
| 201 | auto& kernel = system.Kernel(); | 202 | auto& kernel = system.Kernel(); |
| 202 | kernel.CurrentScheduler()->OnThreadStart(); | 203 | kernel.CurrentScheduler()->OnThreadStart(); |
| 203 | auto* thread = kernel.CurrentScheduler()->GetCurrentThread(); | 204 | auto* thread = kernel.CurrentScheduler()->GetCurrentThread(); |
| 204 | auto& host_context = thread->GetHostContext(); | 205 | auto host_context = thread->GetHostContext(); |
| 205 | host_context->SetRewindPoint(GuestRewindFunction, this); | 206 | host_context->SetRewindPoint(GuestRewindFunction, this); |
| 206 | SingleCoreRunGuestLoop(); | 207 | SingleCoreRunGuestLoop(); |
| 207 | } | 208 | } |
| @@ -245,7 +246,7 @@ void CpuManager::SingleCoreRunSuspendThread() { | |||
| 245 | auto core = kernel.GetCurrentHostThreadID(); | 246 | auto core = kernel.GetCurrentHostThreadID(); |
| 246 | auto& scheduler = *kernel.CurrentScheduler(); | 247 | auto& scheduler = *kernel.CurrentScheduler(); |
| 247 | Kernel::KThread* current_thread = scheduler.GetCurrentThread(); | 248 | Kernel::KThread* current_thread = scheduler.GetCurrentThread(); |
| 248 | Common::Fiber::YieldTo(current_thread->GetHostContext(), core_data[0].host_context); | 249 | Common::Fiber::YieldTo(current_thread->GetHostContext(), core_data[0].host_context.get()); |
| 249 | ASSERT(scheduler.ContextSwitchPending()); | 250 | ASSERT(scheduler.ContextSwitchPending()); |
| 250 | ASSERT(core == kernel.GetCurrentHostThreadID()); | 251 | ASSERT(core == kernel.GetCurrentHostThreadID()); |
| 251 | scheduler.RescheduleCurrentCore(); | 252 | scheduler.RescheduleCurrentCore(); |
| @@ -363,7 +364,7 @@ void CpuManager::RunThread(std::size_t core) { | |||
| 363 | 364 | ||
| 364 | auto current_thread = system.Kernel().CurrentScheduler()->GetCurrentThread(); | 365 | auto current_thread = system.Kernel().CurrentScheduler()->GetCurrentThread(); |
| 365 | data.is_running = true; | 366 | data.is_running = true; |
| 366 | Common::Fiber::YieldTo(data.host_context, current_thread->GetHostContext()); | 367 | Common::Fiber::YieldTo(data.host_context.get(), current_thread->GetHostContext()); |
| 367 | data.is_running = false; | 368 | data.is_running = false; |
| 368 | data.is_paused = true; | 369 | data.is_paused = true; |
| 369 | data.exit_barrier->Wait(); | 370 | data.exit_barrier->Wait(); |
diff --git a/src/core/cpu_manager.h b/src/core/cpu_manager.h index 17420c941..5ea149f1f 100644 --- a/src/core/cpu_manager.h +++ b/src/core/cpu_manager.h | |||
| @@ -83,7 +83,7 @@ private: | |||
| 83 | void RunThread(std::size_t core); | 83 | void RunThread(std::size_t core); |
| 84 | 84 | ||
| 85 | struct CoreData { | 85 | struct CoreData { |
| 86 | std::shared_ptr<Common::Fiber> host_context; | 86 | std::unique_ptr<Common::Fiber> host_context; |
| 87 | std::unique_ptr<Common::Event> enter_barrier; | 87 | std::unique_ptr<Common::Event> enter_barrier; |
| 88 | std::unique_ptr<Common::Event> exit_barrier; | 88 | std::unique_ptr<Common::Event> exit_barrier; |
| 89 | std::atomic<bool> is_running; | 89 | std::atomic<bool> is_running; |
diff --git a/src/core/hle/kernel/k_scheduler.cpp b/src/core/hle/kernel/k_scheduler.cpp index bb5f43b53..465036f3d 100644 --- a/src/core/hle/kernel/k_scheduler.cpp +++ b/src/core/hle/kernel/k_scheduler.cpp | |||
| @@ -608,7 +608,7 @@ void KScheduler::YieldToAnyThread(KernelCore& kernel) { | |||
| 608 | } | 608 | } |
| 609 | 609 | ||
| 610 | KScheduler::KScheduler(Core::System& system, s32 core_id) : system(system), core_id(core_id) { | 610 | KScheduler::KScheduler(Core::System& system, s32 core_id) : system(system), core_id(core_id) { |
| 611 | switch_fiber = std::make_shared<Common::Fiber>(OnSwitch, this); | 611 | switch_fiber = std::make_unique<Common::Fiber>(OnSwitch, this); |
| 612 | state.needs_scheduling.store(true); | 612 | state.needs_scheduling.store(true); |
| 613 | state.interrupt_task_thread_runnable = false; | 613 | state.interrupt_task_thread_runnable = false; |
| 614 | state.should_count_idle = false; | 614 | state.should_count_idle = false; |
| @@ -726,15 +726,15 @@ void KScheduler::ScheduleImpl() { | |||
| 726 | // Save context for previous thread | 726 | // Save context for previous thread |
| 727 | Unload(previous_thread); | 727 | Unload(previous_thread); |
| 728 | 728 | ||
| 729 | std::shared_ptr<Common::Fiber>* old_context; | 729 | Common::Fiber* old_context; |
| 730 | if (previous_thread != nullptr) { | 730 | if (previous_thread != nullptr) { |
| 731 | old_context = &previous_thread->GetHostContext(); | 731 | old_context = previous_thread->GetHostContext(); |
| 732 | } else { | 732 | } else { |
| 733 | old_context = &idle_thread->GetHostContext(); | 733 | old_context = idle_thread->GetHostContext(); |
| 734 | } | 734 | } |
| 735 | guard.unlock(); | 735 | guard.unlock(); |
| 736 | 736 | ||
| 737 | Common::Fiber::YieldTo(*old_context, switch_fiber); | 737 | Common::Fiber::YieldTo(old_context, switch_fiber.get()); |
| 738 | /// When a thread wakes up, the scheduler may have changed to other in another core. | 738 | /// When a thread wakes up, the scheduler may have changed to other in another core. |
| 739 | auto& next_scheduler = *system.Kernel().CurrentScheduler(); | 739 | auto& next_scheduler = *system.Kernel().CurrentScheduler(); |
| 740 | next_scheduler.SwitchContextStep2(); | 740 | next_scheduler.SwitchContextStep2(); |
| @@ -769,13 +769,13 @@ void KScheduler::SwitchToCurrent() { | |||
| 769 | break; | 769 | break; |
| 770 | } | 770 | } |
| 771 | } | 771 | } |
| 772 | std::shared_ptr<Common::Fiber>* next_context; | 772 | Common::Fiber* next_context; |
| 773 | if (next_thread != nullptr) { | 773 | if (next_thread != nullptr) { |
| 774 | next_context = &next_thread->GetHostContext(); | 774 | next_context = next_thread->GetHostContext(); |
| 775 | } else { | 775 | } else { |
| 776 | next_context = &idle_thread->GetHostContext(); | 776 | next_context = idle_thread->GetHostContext(); |
| 777 | } | 777 | } |
| 778 | Common::Fiber::YieldTo(switch_fiber, *next_context); | 778 | Common::Fiber::YieldTo(switch_fiber.get(), next_context); |
| 779 | } while (!is_switch_pending()); | 779 | } while (!is_switch_pending()); |
| 780 | } | 780 | } |
| 781 | } | 781 | } |
diff --git a/src/core/hle/kernel/k_scheduler.h b/src/core/hle/kernel/k_scheduler.h index f595b9a5c..a4285c595 100644 --- a/src/core/hle/kernel/k_scheduler.h +++ b/src/core/hle/kernel/k_scheduler.h | |||
| @@ -68,12 +68,12 @@ public: | |||
| 68 | 68 | ||
| 69 | void OnThreadStart(); | 69 | void OnThreadStart(); |
| 70 | 70 | ||
| 71 | [[nodiscard]] std::shared_ptr<Common::Fiber>& ControlContext() { | 71 | [[nodiscard]] Common::Fiber* ControlContext() { |
| 72 | return switch_fiber; | 72 | return switch_fiber.get(); |
| 73 | } | 73 | } |
| 74 | 74 | ||
| 75 | [[nodiscard]] const std::shared_ptr<Common::Fiber>& ControlContext() const { | 75 | [[nodiscard]] const Common::Fiber* ControlContext() const { |
| 76 | return switch_fiber; | 76 | return switch_fiber.get(); |
| 77 | } | 77 | } |
| 78 | 78 | ||
| 79 | [[nodiscard]] u64 UpdateHighestPriorityThread(KThread* highest_thread); | 79 | [[nodiscard]] u64 UpdateHighestPriorityThread(KThread* highest_thread); |
| @@ -178,7 +178,7 @@ private: | |||
| 178 | 178 | ||
| 179 | KThread* idle_thread; | 179 | KThread* idle_thread; |
| 180 | 180 | ||
| 181 | std::shared_ptr<Common::Fiber> switch_fiber{}; | 181 | std::unique_ptr<Common::Fiber> switch_fiber{}; |
| 182 | 182 | ||
| 183 | struct SchedulingState { | 183 | struct SchedulingState { |
| 184 | std::atomic<bool> needs_scheduling; | 184 | std::atomic<bool> needs_scheduling; |
diff --git a/src/core/hle/kernel/k_thread.cpp b/src/core/hle/kernel/k_thread.cpp index 1661afbd9..f49e31b72 100644 --- a/src/core/hle/kernel/k_thread.cpp +++ b/src/core/hle/kernel/k_thread.cpp | |||
| @@ -991,10 +991,6 @@ void KThread::SetState(ThreadState state) { | |||
| 991 | } | 991 | } |
| 992 | } | 992 | } |
| 993 | 993 | ||
| 994 | std::shared_ptr<Common::Fiber>& KThread::GetHostContext() { | ||
| 995 | return host_context; | ||
| 996 | } | ||
| 997 | |||
| 998 | ResultVal<std::shared_ptr<KThread>> KThread::Create(Core::System& system, ThreadType type_flags, | 994 | ResultVal<std::shared_ptr<KThread>> KThread::Create(Core::System& system, ThreadType type_flags, |
| 999 | std::string name, VAddr entry_point, | 995 | std::string name, VAddr entry_point, |
| 1000 | u32 priority, u64 arg, s32 processor_id, | 996 | u32 priority, u64 arg, s32 processor_id, |
| @@ -1028,7 +1024,7 @@ ResultVal<std::shared_ptr<KThread>> KThread::Create(Core::System& system, Thread | |||
| 1028 | scheduler.AddThread(thread); | 1024 | scheduler.AddThread(thread); |
| 1029 | 1025 | ||
| 1030 | thread->host_context = | 1026 | thread->host_context = |
| 1031 | std::make_shared<Common::Fiber>(std::move(thread_start_func), thread_start_parameter); | 1027 | std::make_unique<Common::Fiber>(std::move(thread_start_func), thread_start_parameter); |
| 1032 | 1028 | ||
| 1033 | return MakeResult<std::shared_ptr<KThread>>(std::move(thread)); | 1029 | return MakeResult<std::shared_ptr<KThread>>(std::move(thread)); |
| 1034 | } | 1030 | } |
diff --git a/src/core/hle/kernel/k_thread.h b/src/core/hle/kernel/k_thread.h index c8ac656a4..a2893d939 100644 --- a/src/core/hle/kernel/k_thread.h +++ b/src/core/hle/kernel/k_thread.h | |||
| @@ -293,7 +293,13 @@ public: | |||
| 293 | return thread_context_64; | 293 | return thread_context_64; |
| 294 | } | 294 | } |
| 295 | 295 | ||
| 296 | [[nodiscard]] std::shared_ptr<Common::Fiber>& GetHostContext(); | 296 | [[nodiscard]] Common::Fiber* GetHostContext() { |
| 297 | return host_context.get(); | ||
| 298 | } | ||
| 299 | |||
| 300 | [[nodiscard]] const Common::Fiber* GetHostContext() const { | ||
| 301 | return host_context.get(); | ||
| 302 | } | ||
| 297 | 303 | ||
| 298 | [[nodiscard]] ThreadState GetState() const { | 304 | [[nodiscard]] ThreadState GetState() const { |
| 299 | return thread_state & ThreadState::Mask; | 305 | return thread_state & ThreadState::Mask; |
| @@ -719,7 +725,7 @@ private: | |||
| 719 | Common::SpinLock context_guard{}; | 725 | Common::SpinLock context_guard{}; |
| 720 | 726 | ||
| 721 | // For emulation | 727 | // For emulation |
| 722 | std::shared_ptr<Common::Fiber> host_context{}; | 728 | std::unique_ptr<Common::Fiber> host_context{}; |
| 723 | 729 | ||
| 724 | // For debugging | 730 | // For debugging |
| 725 | std::vector<KSynchronizationObject*> wait_objects_for_debugging; | 731 | std::vector<KSynchronizationObject*> wait_objects_for_debugging; |
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index cc8fa6576..d04116115 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp | |||
| @@ -2626,8 +2626,7 @@ void Call(Core::System& system, u32 immediate) { | |||
| 2626 | kernel.ExitSVCProfile(); | 2626 | kernel.ExitSVCProfile(); |
| 2627 | 2627 | ||
| 2628 | if (!thread->IsCallingSvc()) { | 2628 | if (!thread->IsCallingSvc()) { |
| 2629 | auto* host_context = thread->GetHostContext().get(); | 2629 | thread->GetHostContext()->Rewind(); |
| 2630 | host_context->Rewind(); | ||
| 2631 | } | 2630 | } |
| 2632 | 2631 | ||
| 2633 | system.EnterDynarmicProfile(); | 2632 | system.EnterDynarmicProfile(); |