yuzu/src/core/hle/kernel/time_manager.cpp

48 lines
1.6 KiB
C++
Raw Normal View History

2020-12-28 19:15:37 +04:00
// Copyright 2020 yuzu Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include "common/assert.h"
#include "core/core.h"
#include "core/core_timing.h"
#include "core/core_timing_util.h"
2021-05-06 05:20:08 +04:00
#include "core/hle/kernel/handle_table.h"
2020-12-28 19:15:37 +04:00
#include "core/hle/kernel/k_scheduler.h"
2021-01-22 04:15:25 +04:00
#include "core/hle/kernel/k_thread.h"
2020-12-28 19:15:37 +04:00
#include "core/hle/kernel/kernel.h"
#include "core/hle/kernel/time_manager.h"
namespace Kernel {
TimeManager::TimeManager(Core::System& system_) : system{system_} {
2021-05-06 05:20:08 +04:00
time_manager_event_type = Core::Timing::CreateEvent(
"Kernel::TimeManagerCallback",
[this](std::uintptr_t thread_handle, std::chrono::nanoseconds) {
std::shared_ptr<KThread> thread;
{
std::lock_guard lock{mutex};
thread = SharedFrom<KThread>(reinterpret_cast<KThread*>(thread_handle));
}
thread->Wakeup();
});
2020-12-28 19:15:37 +04:00
}
2021-01-22 04:15:25 +04:00
void TimeManager::ScheduleTimeEvent(KThread* thread, s64 nanoseconds) {
2020-12-28 19:15:37 +04:00
std::lock_guard lock{mutex};
if (nanoseconds > 0) {
2021-01-22 04:15:25 +04:00
ASSERT(thread);
ASSERT(thread->GetState() != ThreadState::Runnable);
2020-12-28 19:15:37 +04:00
system.CoreTiming().ScheduleEvent(std::chrono::nanoseconds{nanoseconds},
2021-01-22 04:15:25 +04:00
time_manager_event_type,
reinterpret_cast<uintptr_t>(thread));
2020-12-28 19:15:37 +04:00
}
}
2021-01-22 04:15:25 +04:00
void TimeManager::UnscheduleTimeEvent(KThread* thread) {
2020-12-28 19:15:37 +04:00
std::lock_guard lock{mutex};
2021-01-22 04:15:25 +04:00
system.CoreTiming().UnscheduleEvent(time_manager_event_type,
reinterpret_cast<uintptr_t>(thread));
2020-12-28 19:15:37 +04:00
}
} // namespace Kernel