2022-04-23 10:59:50 +02:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2020-02-14 15:56:27 +01:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <memory>
|
2020-11-19 01:19:00 +01:00
|
|
|
#include <mutex>
|
2020-02-14 15:56:27 +01:00
|
|
|
|
|
|
|
namespace Core {
|
|
|
|
class System;
|
|
|
|
} // namespace Core
|
|
|
|
|
|
|
|
namespace Core::Timing {
|
|
|
|
struct EventType;
|
|
|
|
} // namespace Core::Timing
|
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
2020-12-31 08:01:08 +01:00
|
|
|
class KThread;
|
2020-02-14 15:56:27 +01:00
|
|
|
|
2020-02-22 15:27:40 +01:00
|
|
|
/**
|
|
|
|
* The `TimeManager` takes care of scheduling time events on threads and executes their TimeUp
|
|
|
|
* method when the event is triggered.
|
|
|
|
*/
|
2020-02-14 15:56:27 +01:00
|
|
|
class TimeManager {
|
|
|
|
public:
|
2020-02-22 15:27:40 +01:00
|
|
|
explicit TimeManager(Core::System& system);
|
2020-02-14 15:56:27 +01:00
|
|
|
|
2020-02-22 15:27:40 +01:00
|
|
|
/// Schedule a time event on `timetask` thread that will expire in 'nanoseconds'
|
2021-01-20 06:05:24 +01:00
|
|
|
void ScheduleTimeEvent(KThread* time_task, s64 nanoseconds);
|
2020-02-14 15:56:27 +01:00
|
|
|
|
2020-02-22 15:27:40 +01:00
|
|
|
/// Unschedule an existing time event
|
2021-01-20 06:05:24 +01:00
|
|
|
void UnscheduleTimeEvent(KThread* thread);
|
2020-02-27 03:26:53 +01:00
|
|
|
|
2020-02-14 15:56:27 +01:00
|
|
|
private:
|
|
|
|
Core::System& system;
|
|
|
|
std::shared_ptr<Core::Timing::EventType> time_manager_event_type;
|
2020-11-19 01:19:00 +01:00
|
|
|
std::mutex mutex;
|
2020-02-14 15:56:27 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Kernel
|