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

48 lines
1.6 KiB
C++
Raw Normal View History

2020-02-14 09:56:27 -05:00
// Copyright 2020 yuzu Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
2020-02-22 09:27:40 -05:00
#include "common/assert.h"
2020-02-14 09:56:27 -05:00
#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/k_scheduler.h"
#include "core/hle/kernel/k_thread.h"
2020-02-14 09:56:27 -05:00
#include "core/hle/kernel/kernel.h"
#include "core/hle/kernel/time_manager.h"
namespace Kernel {
TimeManager::TimeManager(Core::System& system_) : system{system_} {
2020-02-14 09:56:27 -05: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-02-14 09:56:27 -05:00
});
}
void TimeManager::ScheduleTimeEvent(KThread* thread, s64 nanoseconds) {
std::lock_guard lock{mutex};
2020-02-14 09:56:27 -05:00
if (nanoseconds > 0) {
ASSERT(thread);
ASSERT(thread->GetState() != ThreadState::Runnable);
system.CoreTiming().ScheduleEvent(std::chrono::nanoseconds{nanoseconds},
time_manager_event_type,
reinterpret_cast<uintptr_t>(thread));
2020-02-14 09:56:27 -05:00
}
}
void TimeManager::UnscheduleTimeEvent(KThread* thread) {
std::lock_guard lock{mutex};
system.CoreTiming().UnscheduleEvent(time_manager_event_type,
reinterpret_cast<uintptr_t>(thread));
2020-02-14 09:56:27 -05:00
}
} // namespace Kernel