2020-02-14 14:56:27 +00:00
|
|
|
// Copyright 2020 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <memory>
|
2020-11-19 00:19:00 +00:00
|
|
|
#include <mutex>
|
2020-02-14 14:56:27 +00:00
|
|
|
|
|
|
|
namespace Core {
|
|
|
|
class System;
|
|
|
|
} // namespace Core
|
|
|
|
|
|
|
|
namespace Core::Timing {
|
|
|
|
struct EventType;
|
|
|
|
} // namespace Core::Timing
|
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
2020-12-31 07:01:08 +00:00
|
|
|
class KThread;
|
2020-02-14 14:56:27 +00:00
|
|
|
|
2020-02-22 14:27:40 +00:00
|
|
|
/**
|
|
|
|
* The `TimeManager` takes care of scheduling time events on threads and executes their TimeUp
|
|
|
|
* method when the event is triggered.
|
|
|
|
*/
|
2020-02-14 14:56:27 +00:00
|
|
|
class TimeManager {
|
|
|
|
public:
|
2020-02-22 14:27:40 +00:00
|
|
|
explicit TimeManager(Core::System& system);
|
2020-02-14 14:56:27 +00:00
|
|
|
|
2020-02-22 14:27:40 +00:00
|
|
|
/// Schedule a time event on `timetask` thread that will expire in 'nanoseconds'
|
2021-01-20 05:05:24 +00:00
|
|
|
void ScheduleTimeEvent(KThread* time_task, s64 nanoseconds);
|
2020-02-14 14:56:27 +00:00
|
|
|
|
2020-02-22 14:27:40 +00:00
|
|
|
/// Unschedule an existing time event
|
2021-01-20 05:05:24 +00:00
|
|
|
void UnscheduleTimeEvent(KThread* thread);
|
2020-02-27 02:26:53 +00:00
|
|
|
|
2020-02-14 14:56:27 +00:00
|
|
|
private:
|
|
|
|
Core::System& system;
|
|
|
|
std::shared_ptr<Core::Timing::EventType> time_manager_event_type;
|
2020-11-19 00:19:00 +00:00
|
|
|
std::mutex mutex;
|
2020-02-14 14:56:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Kernel
|