diff options
author | liamwhite <liamwhite@users.noreply.github.com> | 2023-03-10 19:55:11 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-10 19:55:11 +0100 |
commit | 021af4fd0016c49009e3c1ff51ff73aba75b9eb4 (patch) | |
tree | c589832d3b517d96dae79b7263b92fe69a3457ba /src/common/steady_clock.cpp | |
parent | Merge pull request #9916 from liamwhite/fpu (diff) | |
parent | perf_stats: Check multicore first (diff) | |
download | yuzu-021af4fd0016c49009e3c1ff51ff73aba75b9eb4.tar yuzu-021af4fd0016c49009e3c1ff51ff73aba75b9eb4.tar.gz yuzu-021af4fd0016c49009e3c1ff51ff73aba75b9eb4.tar.bz2 yuzu-021af4fd0016c49009e3c1ff51ff73aba75b9eb4.tar.lz yuzu-021af4fd0016c49009e3c1ff51ff73aba75b9eb4.tar.xz yuzu-021af4fd0016c49009e3c1ff51ff73aba75b9eb4.tar.zst yuzu-021af4fd0016c49009e3c1ff51ff73aba75b9eb4.zip |
Diffstat (limited to 'src/common/steady_clock.cpp')
-rw-r--r-- | src/common/steady_clock.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/common/steady_clock.cpp b/src/common/steady_clock.cpp index 0d5908aa7..782859196 100644 --- a/src/common/steady_clock.cpp +++ b/src/common/steady_clock.cpp @@ -23,6 +23,19 @@ static s64 WindowsQueryPerformanceCounter() { QueryPerformanceCounter(&counter); return counter.QuadPart; } + +static s64 GetSystemTimeNS() { + // GetSystemTimePreciseAsFileTime returns the file time in 100ns units. + static constexpr s64 Multiplier = 100; + // Convert Windows epoch to Unix epoch. + static constexpr s64 WindowsEpochToUnixEpochNS = 0x19DB1DED53E8000LL; + + FILETIME filetime; + GetSystemTimePreciseAsFileTime(&filetime); + return Multiplier * ((static_cast<s64>(filetime.dwHighDateTime) << 32) + + static_cast<s64>(filetime.dwLowDateTime)) - + WindowsEpochToUnixEpochNS; +} #endif SteadyClock::time_point SteadyClock::Now() noexcept { @@ -53,4 +66,16 @@ SteadyClock::time_point SteadyClock::Now() noexcept { #endif } +RealTimeClock::time_point RealTimeClock::Now() noexcept { +#if defined(_WIN32) + return time_point{duration{GetSystemTimeNS()}}; +#elif defined(__APPLE__) + return time_point{duration{clock_gettime_nsec_np(CLOCK_REALTIME)}}; +#else + timespec ts; + clock_gettime(CLOCK_REALTIME, &ts); + return time_point{std::chrono::seconds{ts.tv_sec} + std::chrono::nanoseconds{ts.tv_nsec}}; +#endif +} + }; // namespace Common |