summaryrefslogtreecommitdiff
path: root/src/common/wall_clock.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/wall_clock.h')
-rw-r--r--src/common/wall_clock.h55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/common/wall_clock.h b/src/common/wall_clock.h
new file mode 100644
index 000000000..bc7adfbf8
--- /dev/null
+++ b/src/common/wall_clock.h
@@ -0,0 +1,55 @@
1// Copyright 2020 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include <chrono>
8#include <memory>
9
10#include "common/common_types.h"
11
12namespace Common {
13
14class WallClock {
15public:
16 virtual ~WallClock() = default;
17
18 /// Returns current wall time in nanoseconds
19 [[nodiscard]] virtual std::chrono::nanoseconds GetTimeNS() = 0;
20
21 /// Returns current wall time in microseconds
22 [[nodiscard]] virtual std::chrono::microseconds GetTimeUS() = 0;
23
24 /// Returns current wall time in milliseconds
25 [[nodiscard]] virtual std::chrono::milliseconds GetTimeMS() = 0;
26
27 /// Returns current wall time in emulated clock cycles
28 [[nodiscard]] virtual u64 GetClockCycles() = 0;
29
30 /// Returns current wall time in emulated cpu cycles
31 [[nodiscard]] virtual u64 GetCPUCycles() = 0;
32
33 virtual void Pause(bool is_paused) = 0;
34
35 /// Tells if the wall clock, uses the host CPU's hardware clock
36 [[nodiscard]] bool IsNative() const {
37 return is_native;
38 }
39
40protected:
41 WallClock(u64 emulated_cpu_frequency, u64 emulated_clock_frequency, bool is_native)
42 : emulated_cpu_frequency{emulated_cpu_frequency},
43 emulated_clock_frequency{emulated_clock_frequency}, is_native{is_native} {}
44
45 u64 emulated_cpu_frequency;
46 u64 emulated_clock_frequency;
47
48private:
49 bool is_native;
50};
51
52[[nodiscard]] std::unique_ptr<WallClock> CreateBestMatchingClock(u32 emulated_cpu_frequency,
53 u32 emulated_clock_frequency);
54
55} // namespace Common