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.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <mutex>
|
|
|
|
#include <unordered_map>
|
|
|
|
|
|
|
|
#include "core/hle/kernel/object.h"
|
|
|
|
|
|
|
|
namespace Core {
|
|
|
|
class System;
|
|
|
|
} // namespace Core
|
|
|
|
|
|
|
|
namespace Core::Timing {
|
|
|
|
struct EventType;
|
|
|
|
} // namespace Core::Timing
|
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
2021-01-21 05:42:22 +04:00
|
|
|
class KThread;
|
2020-12-28 19:15:37 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The `TimeManager` takes care of scheduling time events on threads and executes their TimeUp
|
|
|
|
* method when the event is triggered.
|
|
|
|
*/
|
|
|
|
class TimeManager {
|
|
|
|
public:
|
|
|
|
explicit TimeManager(Core::System& system);
|
|
|
|
|
|
|
|
/// Schedule a time event on `timetask` thread that will expire in 'nanoseconds'
|
2021-01-21 05:42:22 +04:00
|
|
|
void ScheduleTimeEvent(KThread* time_task, s64 nanoseconds);
|
2020-12-28 19:15:37 +04:00
|
|
|
|
|
|
|
/// Unschedule an existing time event
|
2021-01-21 05:42:22 +04:00
|
|
|
void UnscheduleTimeEvent(KThread* thread);
|
2020-12-28 19:15:37 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
Core::System& system;
|
|
|
|
std::shared_ptr<Core::Timing::EventType> time_manager_event_type;
|
|
|
|
std::mutex mutex;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Kernel
|