diff options
author | bunnei <bunneidev@gmail.com> | 2020-12-04 06:56:02 +0100 |
---|---|---|
committer | bunnei <bunneidev@gmail.com> | 2020-12-06 09:03:24 +0100 |
commit | 4756cb203e8ef09377988eb1b49ca20ef45f4492 (patch) | |
tree | 69aed28dbf048dea702665e68797f14c20650276 /src/core/hle/kernel/k_scoped_scheduler_lock_and_sleep.h | |
parent | hle: kernel: Separate KScheduler from GlobalSchedulerContext class. (diff) | |
download | yuzu-4756cb203e8ef09377988eb1b49ca20ef45f4492.tar yuzu-4756cb203e8ef09377988eb1b49ca20ef45f4492.tar.gz yuzu-4756cb203e8ef09377988eb1b49ca20ef45f4492.tar.bz2 yuzu-4756cb203e8ef09377988eb1b49ca20ef45f4492.tar.lz yuzu-4756cb203e8ef09377988eb1b49ca20ef45f4492.tar.xz yuzu-4756cb203e8ef09377988eb1b49ca20ef45f4492.tar.zst yuzu-4756cb203e8ef09377988eb1b49ca20ef45f4492.zip |
Diffstat (limited to 'src/core/hle/kernel/k_scoped_scheduler_lock_and_sleep.h')
-rw-r--r-- | src/core/hle/kernel/k_scoped_scheduler_lock_and_sleep.h | 56 |
1 files changed, 56 insertions, 0 deletions
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 |