timer.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // Copyright 2015 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include "common/common_types.h"
  6. #include "core/hle/kernel/kernel.h"
  7. namespace Kernel {
  8. class Timer final : public WaitObject {
  9. public:
  10. /**
  11. * Creates a timer
  12. * @param reset_type ResetType describing how to create the timer
  13. * @param name Optional name of timer
  14. * @return The created Timer
  15. */
  16. static SharedPtr<Timer> Create(ResetType reset_type, std::string name = "Unknown");
  17. std::string GetTypeName() const override {
  18. return "Timer";
  19. }
  20. std::string GetName() const override {
  21. return name;
  22. }
  23. static const HandleType HANDLE_TYPE = HandleType::Timer;
  24. HandleType GetHandleType() const override {
  25. return HANDLE_TYPE;
  26. }
  27. ResetType reset_type; ///< The ResetType of this timer
  28. bool signaled; ///< Whether the timer has been signaled or not
  29. std::string name; ///< Name of timer (optional)
  30. u64 initial_delay; ///< The delay until the timer fires for the first time
  31. u64 interval_delay; ///< The delay until the timer fires after the first time
  32. bool ShouldWait(Thread* thread) const override;
  33. void Acquire(Thread* thread) override;
  34. void WakeupAllWaitingThreads() override;
  35. /**
  36. * Starts the timer, with the specified initial delay and interval.
  37. * @param initial Delay until the timer is first fired
  38. * @param interval Delay until the timer is fired after the first time
  39. */
  40. void Set(s64 initial, s64 interval);
  41. void Cancel();
  42. void Clear();
  43. /**
  44. * Signals the timer, waking up any waiting threads and rescheduling it
  45. * for the next interval.
  46. * This method should not be called from outside the timer callback handler,
  47. * lest multiple callback events get scheduled.
  48. */
  49. void Signal(int cycles_late);
  50. private:
  51. Timer();
  52. ~Timer() override;
  53. /// Handle used as userdata to reference this object when inserting into the CoreTiming queue.
  54. Handle callback_handle;
  55. };
  56. /// Initializes the required variables for timers
  57. void TimersInit();
  58. /// Tears down the timer variables
  59. void TimersShutdown();
  60. } // namespace