wall_clock.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. /// Returns current wall time in nanoseconds
  12. virtual std::chrono::nanoseconds GetTimeNS() = 0;
  13. /// Returns current wall time in microseconds
  14. virtual std::chrono::microseconds GetTimeUS() = 0;
  15. /// Returns current wall time in milliseconds
  16. virtual std::chrono::milliseconds GetTimeMS() = 0;
  17. /// Returns current wall time in emulated clock cycles
  18. virtual u64 GetClockCycles() = 0;
  19. /// Returns current wall time in emulated cpu cycles
  20. virtual u64 GetCPUCycles() = 0;
  21. /// Tells if the wall clock, uses the host CPU's hardware clock
  22. bool IsNative() const {
  23. return is_native;
  24. }
  25. protected:
  26. WallClock(u64 emulated_cpu_frequency, u64 emulated_clock_frequency, bool is_native)
  27. : emulated_cpu_frequency{emulated_cpu_frequency},
  28. emulated_clock_frequency{emulated_clock_frequency}, is_native{is_native} {}
  29. u64 emulated_cpu_frequency;
  30. u64 emulated_clock_frequency;
  31. private:
  32. bool is_native;
  33. };
  34. std::unique_ptr<WallClock> CreateBestMatchingClock(u32 emulated_cpu_frequency,
  35. u32 emulated_clock_frequency);
  36. } // namespace Common