From 4756cb203e8ef09377988eb1b49ca20ef45f4492 Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 3 Dec 2020 21:56:02 -0800 Subject: hle: kernel: Separate KScopedSchedulerLockAndSleep from k_scheduler. --- .../hle/kernel/k_scoped_scheduler_lock_and_sleep.h | 56 ++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/core/hle/kernel/k_scoped_scheduler_lock_and_sleep.h (limited to 'src/core/hle/kernel/k_scoped_scheduler_lock_and_sleep.h') diff --git a/src/core/hle/kernel/k_scoped_scheduler_lock_and_sleep.h b/src/core/hle/kernel/k_scoped_scheduler_lock_and_sleep.h new file mode 100644 index 000000000..f11a62216 --- /dev/null +++ b/src/core/hle/kernel/k_scoped_scheduler_lock_and_sleep.h @@ -0,0 +1,56 @@ +// Copyright 2020 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +// This file references various implementation details from Atmosphere, an open-source firmware for +// the Nintendo Switch. Copyright 2018-2020 Atmosphere-NX. + +#pragma once + +#include "common/common_types.h" +#include "core/hle/kernel/kernel.h" +#include "core/hle/kernel/thread.h" +#include "core/hle/kernel/time_manager.h" + +namespace Kernel { + +class KScopedSchedulerLockAndSleep { +private: + KernelCore& kernel; + s64 timeout_tick{}; + Thread* thread{}; + Handle* event_handle{}; + +public: + explicit KScopedSchedulerLockAndSleep(KernelCore& kernel, Thread* t, s64 timeout) + : kernel(kernel), timeout_tick(timeout), thread(t) { + /* Lock the scheduler. */ + kernel.GlobalSchedulerContext().scheduler_lock.Lock(); + } + + explicit KScopedSchedulerLockAndSleep(KernelCore& kernel, Handle& event_handle, Thread* t, + s64 timeout) + : kernel(kernel), event_handle(&event_handle), timeout_tick(timeout), thread(t) { + /* Lock the scheduler. */ + kernel.GlobalSchedulerContext().scheduler_lock.Lock(); + } + + ~KScopedSchedulerLockAndSleep() { + /* Register the sleep. */ + if (this->timeout_tick > 0) { + auto& time_manager = kernel.TimeManager(); + Handle handle{}; + time_manager.ScheduleTimeEvent(event_handle ? *event_handle : handle, this->thread, + this->timeout_tick); + } + + /* Unlock the scheduler. */ + kernel.GlobalSchedulerContext().scheduler_lock.Unlock(); + } + + void CancelSleep() { + this->timeout_tick = 0; + } +}; + +} // namespace Kernel -- cgit v1.2.3 From bc59ca92b6540efbcf45baab79d0f498eb103f30 Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 3 Dec 2020 22:44:06 -0800 Subject: kernel: KScopedSchedulerLockAndSleep: Remove unused ctor. --- .../hle/kernel/k_scoped_scheduler_lock_and_sleep.h | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) (limited to 'src/core/hle/kernel/k_scoped_scheduler_lock_and_sleep.h') diff --git a/src/core/hle/kernel/k_scoped_scheduler_lock_and_sleep.h b/src/core/hle/kernel/k_scoped_scheduler_lock_and_sleep.h index f11a62216..16f470923 100644 --- a/src/core/hle/kernel/k_scoped_scheduler_lock_and_sleep.h +++ b/src/core/hle/kernel/k_scoped_scheduler_lock_and_sleep.h @@ -8,6 +8,7 @@ #pragma once #include "common/common_types.h" +#include "core/hle/kernel/handle_table.h" #include "core/hle/kernel/kernel.h" #include "core/hle/kernel/thread.h" #include "core/hle/kernel/time_manager.h" @@ -17,20 +18,16 @@ namespace Kernel { class KScopedSchedulerLockAndSleep { private: KernelCore& kernel; - s64 timeout_tick{}; + Handle& event_handle; Thread* thread{}; - Handle* event_handle{}; + s64 timeout_tick{}; public: - explicit KScopedSchedulerLockAndSleep(KernelCore& kernel, Thread* t, s64 timeout) - : kernel(kernel), timeout_tick(timeout), thread(t) { - /* Lock the scheduler. */ - kernel.GlobalSchedulerContext().scheduler_lock.Lock(); - } - explicit KScopedSchedulerLockAndSleep(KernelCore& kernel, Handle& event_handle, Thread* t, s64 timeout) - : kernel(kernel), event_handle(&event_handle), timeout_tick(timeout), thread(t) { + : kernel(kernel), event_handle(event_handle), thread(t), timeout_tick(timeout) { + event_handle = InvalidHandle; + /* Lock the scheduler. */ kernel.GlobalSchedulerContext().scheduler_lock.Lock(); } @@ -38,10 +35,7 @@ public: ~KScopedSchedulerLockAndSleep() { /* Register the sleep. */ if (this->timeout_tick > 0) { - auto& time_manager = kernel.TimeManager(); - Handle handle{}; - time_manager.ScheduleTimeEvent(event_handle ? *event_handle : handle, this->thread, - this->timeout_tick); + kernel.TimeManager().ScheduleTimeEvent(event_handle, this->thread, this->timeout_tick); } /* Unlock the scheduler. */ -- cgit v1.2.3 From b1326d9230f7c1f33960d2816042b1a41d3b839f Mon Sep 17 00:00:00 2001 From: bunnei Date: Fri, 4 Dec 2020 23:37:35 -0800 Subject: hle: kernel: Use C++ style comments in KScheduler, etc. --- src/core/hle/kernel/k_scoped_scheduler_lock_and_sleep.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/core/hle/kernel/k_scoped_scheduler_lock_and_sleep.h') diff --git a/src/core/hle/kernel/k_scoped_scheduler_lock_and_sleep.h b/src/core/hle/kernel/k_scoped_scheduler_lock_and_sleep.h index 16f470923..d1cc5dda7 100644 --- a/src/core/hle/kernel/k_scoped_scheduler_lock_and_sleep.h +++ b/src/core/hle/kernel/k_scoped_scheduler_lock_and_sleep.h @@ -28,17 +28,17 @@ public: : kernel(kernel), event_handle(event_handle), thread(t), timeout_tick(timeout) { event_handle = InvalidHandle; - /* Lock the scheduler. */ + // Lock the scheduler. kernel.GlobalSchedulerContext().scheduler_lock.Lock(); } ~KScopedSchedulerLockAndSleep() { - /* Register the sleep. */ + // Register the sleep. if (this->timeout_tick > 0) { kernel.TimeManager().ScheduleTimeEvent(event_handle, this->thread, this->timeout_tick); } - /* Unlock the scheduler. */ + // Unlock the scheduler. kernel.GlobalSchedulerContext().scheduler_lock.Unlock(); } -- cgit v1.2.3 From ed4d1e2adefa4775dc1a950d7db84c7935ae7324 Mon Sep 17 00:00:00 2001 From: bunnei Date: Sat, 5 Dec 2020 00:07:44 -0800 Subject: hle: kernel: KScopedSchedulerLockAndSleep: Various style fixes based on code review feedback. --- src/core/hle/kernel/k_scoped_scheduler_lock_and_sleep.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/core/hle/kernel/k_scoped_scheduler_lock_and_sleep.h') diff --git a/src/core/hle/kernel/k_scoped_scheduler_lock_and_sleep.h b/src/core/hle/kernel/k_scoped_scheduler_lock_and_sleep.h index d1cc5dda7..2bb3817fa 100644 --- a/src/core/hle/kernel/k_scoped_scheduler_lock_and_sleep.h +++ b/src/core/hle/kernel/k_scoped_scheduler_lock_and_sleep.h @@ -16,12 +16,6 @@ namespace Kernel { class KScopedSchedulerLockAndSleep { -private: - KernelCore& kernel; - Handle& event_handle; - Thread* thread{}; - s64 timeout_tick{}; - public: explicit KScopedSchedulerLockAndSleep(KernelCore& kernel, Handle& event_handle, Thread* t, s64 timeout) @@ -45,6 +39,12 @@ public: void CancelSleep() { this->timeout_tick = 0; } + +private: + KernelCore& kernel; + Handle& event_handle; + Thread* thread{}; + s64 timeout_tick{}; }; } // namespace Kernel -- cgit v1.2.3