wall_clock.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 <chrono>
  6. #include <memory>
  7. #include "common/common_types.h"
  8. namespace Common {
  9. class WallClock {
  10. public:
  11. virtual ~WallClock() = default;
  12. /// Returns current wall time in nanoseconds
  13. [[nodiscard]] virtual std::chrono::nanoseconds GetTimeNS() = 0;
  14. /// Returns current wall time in microseconds
  15. [[nodiscard]] virtual std::chrono::microseconds GetTimeUS() = 0;
  16. /// Returns current wall time in milliseconds
  17. [[nodiscard]] virtual std::chrono::milliseconds GetTimeMS() = 0;
  18. /// Returns current wall time in emulated clock cycles
  19. [[nodiscard]] virtual u64 GetClockCycles() = 0;
  20. /// Returns current wall time in emulated cpu cycles
  21. [[nodiscard]] virtual u64 GetCPUCycles() = 0;
  22. virtual void Pause(bool is_paused) = 0;
  23. /// Tells if the wall clock, uses the host CPU's hardware clock
  24. [[nodiscard]] bool IsNative() const {
  25. return is_native;
  26. }
  27. protected:
  28. explicit WallClock(u64 emulated_cpu_frequency_, u64 emulated_clock_frequency_, bool is_native_)
  29. : emulated_cpu_frequency{emulated_cpu_frequency_},
  30. emulated_clock_frequency{emulated_clock_frequency_}, is_native{is_native_} {}
  31. u64 emulated_cpu_frequency;
  32. u64 emulated_clock_frequency;
  33. private:
  34. bool is_native;
  35. };
  36. [[nodiscard]] std::unique_ptr<WallClock> CreateBestMatchingClock(u32 emulated_cpu_frequency,
  37. u32 emulated_clock_frequency);
  38. } // namespace Common