diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/hle/kernel/k_scheduler.cpp | 16 | ||||
| -rw-r--r-- | src/core/hle/kernel/k_scheduler.h | 6 |
2 files changed, 9 insertions, 13 deletions
diff --git a/src/core/hle/kernel/k_scheduler.cpp b/src/core/hle/kernel/k_scheduler.cpp index d1df97305..c048d86a3 100644 --- a/src/core/hle/kernel/k_scheduler.cpp +++ b/src/core/hle/kernel/k_scheduler.cpp | |||
| @@ -623,7 +623,7 @@ KThread* KScheduler::GetCurrentThread() const { | |||
| 623 | if (auto result = current_thread.load(); result) { | 623 | if (auto result = current_thread.load(); result) { |
| 624 | return result; | 624 | return result; |
| 625 | } | 625 | } |
| 626 | return idle_thread; | 626 | return idle_thread.get(); |
| 627 | } | 627 | } |
| 628 | 628 | ||
| 629 | u64 KScheduler::GetLastContextSwitchTicks() const { | 629 | u64 KScheduler::GetLastContextSwitchTicks() const { |
| @@ -708,7 +708,7 @@ void KScheduler::ScheduleImpl() { | |||
| 708 | 708 | ||
| 709 | // We never want to schedule a null thread, so use the idle thread if we don't have a next. | 709 | // We never want to schedule a null thread, so use the idle thread if we don't have a next. |
| 710 | if (next_thread == nullptr) { | 710 | if (next_thread == nullptr) { |
| 711 | next_thread = idle_thread; | 711 | next_thread = idle_thread.get(); |
| 712 | } | 712 | } |
| 713 | 713 | ||
| 714 | // If we're not actually switching thread, there's nothing to do. | 714 | // If we're not actually switching thread, there's nothing to do. |
| @@ -769,7 +769,7 @@ void KScheduler::SwitchToCurrent() { | |||
| 769 | break; | 769 | break; |
| 770 | } | 770 | } |
| 771 | } | 771 | } |
| 772 | auto thread = next_thread ? next_thread : idle_thread; | 772 | auto thread = next_thread ? next_thread : idle_thread.get(); |
| 773 | Common::Fiber::YieldTo(switch_fiber, *thread->GetHostContext()); | 773 | Common::Fiber::YieldTo(switch_fiber, *thread->GetHostContext()); |
| 774 | } while (!is_switch_pending()); | 774 | } while (!is_switch_pending()); |
| 775 | } | 775 | } |
| @@ -792,13 +792,9 @@ void KScheduler::UpdateLastContextSwitchTime(KThread* thread, Process* process) | |||
| 792 | } | 792 | } |
| 793 | 793 | ||
| 794 | void KScheduler::Initialize() { | 794 | void KScheduler::Initialize() { |
| 795 | std::string name = "Idle Thread Id:" + std::to_string(core_id); | 795 | idle_thread = std::make_unique<KThread>(system.Kernel()); |
| 796 | std::function<void(void*)> init_func = Core::CpuManager::GetIdleThreadStartFunc(); | 796 | ASSERT(KThread::InitializeIdleThread(system, idle_thread.get(), core_id).IsSuccess()); |
| 797 | void* init_func_parameter = system.GetCpuManager().GetStartFuncParamater(); | 797 | idle_thread->SetName(fmt::format("IdleThread:{}", core_id)); |
| 798 | auto thread_res = KThread::CreateThread( | ||
| 799 | system, ThreadType::Main, name, 0, KThread::IdleThreadPriority, 0, | ||
| 800 | static_cast<u32>(core_id), 0, nullptr, std::move(init_func), init_func_parameter); | ||
| 801 | idle_thread = thread_res.Unwrap().get(); | ||
| 802 | } | 798 | } |
| 803 | 799 | ||
| 804 | KScopedSchedulerLock::KScopedSchedulerLock(KernelCore& kernel) | 800 | KScopedSchedulerLock::KScopedSchedulerLock(KernelCore& kernel) |
diff --git a/src/core/hle/kernel/k_scheduler.h b/src/core/hle/kernel/k_scheduler.h index 8e32865aa..8cb5f6f36 100644 --- a/src/core/hle/kernel/k_scheduler.h +++ b/src/core/hle/kernel/k_scheduler.h | |||
| @@ -51,7 +51,7 @@ public: | |||
| 51 | 51 | ||
| 52 | /// Returns true if the scheduler is idle | 52 | /// Returns true if the scheduler is idle |
| 53 | [[nodiscard]] bool IsIdle() const { | 53 | [[nodiscard]] bool IsIdle() const { |
| 54 | return GetCurrentThread() == idle_thread; | 54 | return GetCurrentThread() == idle_thread.get(); |
| 55 | } | 55 | } |
| 56 | 56 | ||
| 57 | /// Gets the timestamp for the last context switch in ticks. | 57 | /// Gets the timestamp for the last context switch in ticks. |
| @@ -173,12 +173,12 @@ private: | |||
| 173 | KThread* prev_thread{}; | 173 | KThread* prev_thread{}; |
| 174 | std::atomic<KThread*> current_thread{}; | 174 | std::atomic<KThread*> current_thread{}; |
| 175 | 175 | ||
| 176 | KThread* idle_thread; | 176 | std::unique_ptr<KThread> idle_thread; |
| 177 | 177 | ||
| 178 | std::shared_ptr<Common::Fiber> switch_fiber{}; | 178 | std::shared_ptr<Common::Fiber> switch_fiber{}; |
| 179 | 179 | ||
| 180 | struct SchedulingState { | 180 | struct SchedulingState { |
| 181 | std::atomic<bool> needs_scheduling; | 181 | std::atomic<bool> needs_scheduling{}; |
| 182 | bool interrupt_task_thread_runnable{}; | 182 | bool interrupt_task_thread_runnable{}; |
| 183 | bool should_count_idle{}; | 183 | bool should_count_idle{}; |
| 184 | u64 idle_count{}; | 184 | u64 idle_count{}; |