diff options
author | Fernando Sahmkow <fsahmkow27@gmail.com> | 2020-02-14 15:56:27 +0100 |
---|---|---|
committer | FernandoS27 <fsahmkow27@gmail.com> | 2020-02-22 16:18:07 +0100 |
commit | 5c90d22f3d92b9be818b19e03dd57eb217eb6567 (patch) | |
tree | 206a925ef68687d7b90e2b11d9d68bc42f2ce9d3 /src/core/hle/kernel/time_manager.cpp | |
parent | Kernel: Rename ThreadCallbackHandleTable and Setup Thread Ids on Kernel. (diff) | |
download | yuzu-5c90d22f3d92b9be818b19e03dd57eb217eb6567.tar yuzu-5c90d22f3d92b9be818b19e03dd57eb217eb6567.tar.gz yuzu-5c90d22f3d92b9be818b19e03dd57eb217eb6567.tar.bz2 yuzu-5c90d22f3d92b9be818b19e03dd57eb217eb6567.tar.lz yuzu-5c90d22f3d92b9be818b19e03dd57eb217eb6567.tar.xz yuzu-5c90d22f3d92b9be818b19e03dd57eb217eb6567.tar.zst yuzu-5c90d22f3d92b9be818b19e03dd57eb217eb6567.zip |
Diffstat (limited to 'src/core/hle/kernel/time_manager.cpp')
-rw-r--r-- | src/core/hle/kernel/time_manager.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/core/hle/kernel/time_manager.cpp b/src/core/hle/kernel/time_manager.cpp new file mode 100644 index 000000000..0b3e464d0 --- /dev/null +++ b/src/core/hle/kernel/time_manager.cpp @@ -0,0 +1,42 @@ +// Copyright 2020 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include "core/core.h" +#include "core/core_timing.h" +#include "core/core_timing_util.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" + +namespace Kernel { + +TimeManager::TimeManager(Core::System& system) : system{system} { + time_manager_event_type = Core::Timing::CreateEvent( + "Kernel::TimeManagerCallback", [this](u64 thread_handle, [[maybe_unused]] s64 cycles_late) { + Handle proper_handle = static_cast<Handle>(thread_handle); + std::shared_ptr<Thread> thread = + this->system.Kernel().RetrieveThreadFromGlobalHandleTable(proper_handle); + thread->ResumeFromWait(); + }); +} + +void TimeManager::ScheduleTimeEvent(Handle& event_handle, Thread* timetask, s64 nanoseconds) { + if (nanoseconds > 0) { + ASSERT(timetask); + event_handle = timetask->GetGlobalHandle(); + const s64 cycles = Core::Timing::nsToCycles(std::chrono::nanoseconds{nanoseconds}); + system.CoreTiming().ScheduleEvent(cycles, time_manager_event_type, event_handle); + } else { + event_handle = InvalidHandle; + } +} + +void TimeManager::UnscheduleTimeEvent(Handle event_handle) { + if (event_handle != InvalidHandle) { + system.CoreTiming().UnscheduleEvent(time_manager_event_type, event_handle); + } +} + +} // namespace Kernel |