|
|
@ -623,7 +623,7 @@ KThread* KScheduler::GetCurrentThread() const {
|
|
|
|
if (auto result = current_thread.load(); result) {
|
|
|
|
if (auto result = current_thread.load(); result) {
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return idle_thread;
|
|
|
|
return idle_thread.get();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
u64 KScheduler::GetLastContextSwitchTicks() const {
|
|
|
|
u64 KScheduler::GetLastContextSwitchTicks() const {
|
|
|
@ -708,7 +708,7 @@ void KScheduler::ScheduleImpl() {
|
|
|
|
|
|
|
|
|
|
|
|
// We never want to schedule a null thread, so use the idle thread if we don't have a next.
|
|
|
|
// We never want to schedule a null thread, so use the idle thread if we don't have a next.
|
|
|
|
if (next_thread == nullptr) {
|
|
|
|
if (next_thread == nullptr) {
|
|
|
|
next_thread = idle_thread;
|
|
|
|
next_thread = idle_thread.get();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// If we're not actually switching thread, there's nothing to do.
|
|
|
|
// If we're not actually switching thread, there's nothing to do.
|
|
|
@ -769,7 +769,7 @@ void KScheduler::SwitchToCurrent() {
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
auto thread = next_thread ? next_thread : idle_thread;
|
|
|
|
auto thread = next_thread ? next_thread : idle_thread.get();
|
|
|
|
Common::Fiber::YieldTo(switch_fiber, *thread->GetHostContext());
|
|
|
|
Common::Fiber::YieldTo(switch_fiber, *thread->GetHostContext());
|
|
|
|
} while (!is_switch_pending());
|
|
|
|
} while (!is_switch_pending());
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -792,13 +792,9 @@ void KScheduler::UpdateLastContextSwitchTime(KThread* thread, Process* process)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void KScheduler::Initialize() {
|
|
|
|
void KScheduler::Initialize() {
|
|
|
|
std::string name = "Idle Thread Id:" + std::to_string(core_id);
|
|
|
|
idle_thread = std::make_unique<KThread>(system.Kernel());
|
|
|
|
std::function<void(void*)> init_func = Core::CpuManager::GetIdleThreadStartFunc();
|
|
|
|
ASSERT(KThread::InitializeIdleThread(system, idle_thread.get(), core_id).IsSuccess());
|
|
|
|
void* init_func_parameter = system.GetCpuManager().GetStartFuncParamater();
|
|
|
|
idle_thread->SetName(fmt::format("IdleThread:{}", core_id));
|
|
|
|
auto thread_res = KThread::CreateThread(
|
|
|
|
|
|
|
|
system, ThreadType::Main, name, 0, KThread::IdleThreadPriority, 0,
|
|
|
|
|
|
|
|
static_cast<u32>(core_id), 0, nullptr, std::move(init_func), init_func_parameter);
|
|
|
|
|
|
|
|
idle_thread = thread_res.Unwrap().get();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
KScopedSchedulerLock::KScopedSchedulerLock(KernelCore& kernel)
|
|
|
|
KScopedSchedulerLock::KScopedSchedulerLock(KernelCore& kernel)
|
|
|
|