Debian Codegraph @

Source/Core/Common/Timer.h

raw symbols SCIP
1 // Copyright 2008 Dolphin Emulator Project
2 // SPDX-License-Identifier: GPL-2.0-or-later
3
4 #pragma once
5
6 #include "Common/CommonTypes.h"
7
8 namespace Common
9 {
10 class Timer
11 {
12 public:
13 static u64 NowUs();
14 static u64 NowMs();
15
16 void Start();
17 // Start(), then decrement start time by the offset.
18 // Effectively "resumes" a timer
19 void StartWithOffset(u64 offset);
20 void Stop();
21 u64 ElapsedMs() const;
22
23 // The rest of these functions probably belong somewhere else
24 static u64 GetLocalTimeSinceJan1970();
25
26 static void IncreaseResolution();
27 static void RestoreResolution();
28
29 private:
30 u64 m_start_ms{0};
31 u64 m_end_ms{0};
32 bool m_running{false};
33 };
34
35 class PrecisionTimer
36 {
37 public:
38 PrecisionTimer();
39 ~PrecisionTimer();
40
41 PrecisionTimer(const PrecisionTimer&) = delete;
42 PrecisionTimer& operator=(const PrecisionTimer&) = delete;
43
44 void SleepUntil(Clock::time_point);
45
46 private:
47 #ifdef _WIN32
48 // Using void* to avoid including Windows.h in this header just for HANDLE.
49 void* m_timer_handle;
50 #endif
51 };
52
53 // Similar to std::chrono::steady_clock except this clock
54 // specifically does *not* count time while the system is suspended.
55 class SteadyAwakeClock
56 {
57 public:
58 using rep = s64;
59 using period = std::nano;
60 using duration = std::chrono::duration<rep, period>;
61 using time_point = std::chrono::time_point<SteadyAwakeClock>;
62
63 static constexpr bool is_steady = true;
64
65 static time_point now();
66 };
67
68 } // Namespace Common