diff options
Diffstat (limited to 'src/common')
| -rw-r--r-- | src/common/wall_clock.h | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/common/wall_clock.h b/src/common/wall_clock.h index a73e6e644..56c18ca25 100644 --- a/src/common/wall_clock.h +++ b/src/common/wall_clock.h | |||
| @@ -38,6 +38,22 @@ public: | |||
| 38 | /// @returns Whether the clock directly uses the host's hardware clock. | 38 | /// @returns Whether the clock directly uses the host's hardware clock. |
| 39 | virtual bool IsNative() const = 0; | 39 | virtual bool IsNative() const = 0; |
| 40 | 40 | ||
| 41 | static inline u64 NSToCNTPCT(u64 ns) { | ||
| 42 | return ns * NsToCNTPCTRatio::num / NsToCNTPCTRatio::den; | ||
| 43 | } | ||
| 44 | |||
| 45 | static inline u64 USToCNTPCT(u64 us) { | ||
| 46 | return us * UsToCNTPCTRatio::num / UsToCNTPCTRatio::den; | ||
| 47 | } | ||
| 48 | |||
| 49 | static inline u64 CNTPCTToNS(u64 cntpct) { | ||
| 50 | return cntpct * NsToCNTPCTRatio::den / NsToCNTPCTRatio::num; | ||
| 51 | } | ||
| 52 | |||
| 53 | static inline u64 CNTPCTToUS(u64 cntpct) { | ||
| 54 | return cntpct * UsToCNTPCTRatio::den / UsToCNTPCTRatio::num; | ||
| 55 | } | ||
| 56 | |||
| 41 | protected: | 57 | protected: |
| 42 | using NsRatio = std::nano; | 58 | using NsRatio = std::nano; |
| 43 | using UsRatio = std::micro; | 59 | using UsRatio = std::micro; |
| @@ -46,6 +62,7 @@ protected: | |||
| 46 | using NsToUsRatio = std::ratio_divide<std::nano, std::micro>; | 62 | using NsToUsRatio = std::ratio_divide<std::nano, std::micro>; |
| 47 | using NsToMsRatio = std::ratio_divide<std::nano, std::milli>; | 63 | using NsToMsRatio = std::ratio_divide<std::nano, std::milli>; |
| 48 | using NsToCNTPCTRatio = std::ratio<CNTFRQ, std::nano::den>; | 64 | using NsToCNTPCTRatio = std::ratio<CNTFRQ, std::nano::den>; |
| 65 | using UsToCNTPCTRatio = std::ratio<CNTFRQ, std::micro::den>; | ||
| 49 | }; | 66 | }; |
| 50 | 67 | ||
| 51 | std::unique_ptr<WallClock> CreateOptimalClock(); | 68 | std::unique_ptr<WallClock> CreateOptimalClock(); |