timer.h 2.2 KB

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