2020-02-14 06:56:27 -08: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-18 16:19:00 -08:00
|
|
|
#include <mutex>
|
2020-02-26 18:26:53 -08:00
|
|
|
#include <unordered_map>
|
2020-02-14 06:56:27 -08:00
|
|
|
|
|
|
|
#include "core/hle/kernel/object.h"
|
|
|
|
|
|
|
|
namespace Core {
|
|
|
|
class System;
|
|
|
|
} // namespace Core
|
|
|
|
|
|
|
|
namespace Core::Timing {
|
|
|
|
struct EventType;
|
|
|
|
} // namespace Core::Timing
|
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
2020-12-30 23:01:08 -08:00
|
|
|
class KThread;
|
2020-02-14 06:56:27 -08:00
|
|
|
|
2020-02-22 06:27:40 -08:00
|
|
|
/**
|
|
|
|
* The `TimeManager` takes care of scheduling time events on threads and executes their TimeUp
|
|
|
|
* method when the event is triggered.
|
|
|
|
*/
|
2020-02-14 06:56:27 -08:00
|
|
|
class TimeManager {
|
|
|
|
public:
|
2020-02-22 06:27:40 -08:00
|
|
|
explicit TimeManager(Core::System& system);
|
2020-02-14 06:56:27 -08:00
|
|
|
|
2020-02-22 06:27:40 -08:00
|
|
|
/// Schedule a time event on `timetask` thread that will expire in 'nanoseconds'
|
|
|
|
/// returns a non-invalid handle in `event_handle` if correctly scheduled
|
2020-12-30 23:01:08 -08:00
|
|
|
void ScheduleTimeEvent(Handle& event_handle, KThread* timetask, s64 nanoseconds);
|
2020-02-14 06:56:27 -08:00
|
|
|
|
2020-02-22 06:27:40 -08:00
|
|
|
/// Unschedule an existing time event
|
2020-02-14 06:56:27 -08:00
|
|
|
void UnscheduleTimeEvent(Handle event_handle);
|
|
|
|
|
2020-12-30 23:01:08 -08:00
|
|
|
void CancelTimeEvent(KThread* time_task);
|
2020-02-26 18:26:53 -08:00
|
|
|
|
2020-02-14 06:56:27 -08:00
|
|
|
private:
|
|
|
|
Core::System& system;
|
|
|
|
std::shared_ptr<Core::Timing::EventType> time_manager_event_type;
|
2020-02-26 18:26:53 -08:00
|
|
|
std::unordered_map<Handle, bool> cancelled_events;
|
2020-11-18 16:19:00 -08:00
|
|
|
std::mutex mutex;
|
2020-02-14 06:56:27 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Kernel
|