diff options
| author | 2022-07-02 12:33:49 -0400 | |
|---|---|---|
| committer | 2022-07-02 12:33:49 -0400 | |
| commit | ed0319cfed2c99e6366aaf725d96bb28a9332e4d (patch) | |
| tree | 1598e6d320005e0d177106e28ebc6728234f1f24 /src/core/hle/kernel | |
| parent | Merge pull request #7454 from FernandoS27/new-core-timing (diff) | |
| download | yuzu-ed0319cfed2c99e6366aaf725d96bb28a9332e4d.tar.gz yuzu-ed0319cfed2c99e6366aaf725d96bb28a9332e4d.tar.xz yuzu-ed0319cfed2c99e6366aaf725d96bb28a9332e4d.zip | |
common/fiber: make fibers easier to use
Diffstat (limited to 'src/core/hle/kernel')
| -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 |
4 files changed, 7 insertions, 19 deletions
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 | ||