time_manager.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright 2020 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <memory>
  6. #include <unordered_map>
  7. #include "core/hle/kernel/object.h"
  8. namespace Core {
  9. class System;
  10. } // namespace Core
  11. namespace Core::Timing {
  12. struct EventType;
  13. } // namespace Core::Timing
  14. namespace Kernel {
  15. class Thread;
  16. /**
  17. * The `TimeManager` takes care of scheduling time events on threads and executes their TimeUp
  18. * method when the event is triggered.
  19. */
  20. class TimeManager {
  21. public:
  22. explicit TimeManager(Core::System& system);
  23. /// Schedule a time event on `timetask` thread that will expire in 'nanoseconds'
  24. /// returns a non-invalid handle in `event_handle` if correctly scheduled
  25. void ScheduleTimeEvent(Handle& event_handle, Thread* timetask, s64 nanoseconds);
  26. /// Unschedule an existing time event
  27. void UnscheduleTimeEvent(Handle event_handle);
  28. void CancelTimeEvent(Thread* time_task);
  29. private:
  30. Core::System& system;
  31. std::shared_ptr<Core::Timing::EventType> time_manager_event_type;
  32. std::unordered_map<Handle, bool> cancelled_events;
  33. };
  34. } // namespace Kernel