mirror of
https://git.suyu.dev/suyu/suyu.git
synced 2024-11-27 13:56:27 -05:00
99ceb03a1c
This formats all copyright comments according to SPDX formatting guidelines. Additionally, this resolves the remaining GPLv2 only licensed files by relicensing them to GPLv2.0-or-later.
42 lines
1.6 KiB
C++
42 lines
1.6 KiB
C++
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
#include "common/assert.h"
|
|
#include "core/core.h"
|
|
#include "core/core_timing.h"
|
|
#include "core/hle/kernel/k_scheduler.h"
|
|
#include "core/hle/kernel/k_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](std::uintptr_t thread_handle, std::chrono::nanoseconds) {
|
|
KThread* thread = reinterpret_cast<KThread*>(thread_handle);
|
|
{
|
|
KScopedSchedulerLock sl(system.Kernel());
|
|
thread->OnTimer();
|
|
}
|
|
});
|
|
}
|
|
|
|
void TimeManager::ScheduleTimeEvent(KThread* thread, s64 nanoseconds) {
|
|
std::scoped_lock lock{mutex};
|
|
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));
|
|
}
|
|
}
|
|
|
|
void TimeManager::UnscheduleTimeEvent(KThread* thread) {
|
|
std::scoped_lock lock{mutex};
|
|
system.CoreTiming().UnscheduleEvent(time_manager_event_type,
|
|
reinterpret_cast<uintptr_t>(thread));
|
|
}
|
|
|
|
} // namespace Kernel
|