time_manager.h 952 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 <mutex>
  7. namespace Core {
  8. class System;
  9. } // namespace Core
  10. namespace Core::Timing {
  11. struct EventType;
  12. } // namespace Core::Timing
  13. namespace Kernel {
  14. class KThread;
  15. /**
  16. * The `TimeManager` takes care of scheduling time events on threads and executes their TimeUp
  17. * method when the event is triggered.
  18. */
  19. class TimeManager {
  20. public:
  21. explicit TimeManager(Core::System& system);
  22. /// Schedule a time event on `timetask` thread that will expire in 'nanoseconds'
  23. void ScheduleTimeEvent(KThread* time_task, s64 nanoseconds);
  24. /// Unschedule an existing time event
  25. void UnscheduleTimeEvent(KThread* thread);
  26. private:
  27. Core::System& system;
  28. std::shared_ptr<Core::Timing::EventType> time_manager_event_type;
  29. std::mutex mutex;
  30. };
  31. } // namespace Kernel