From 075d17f8ada47e990fe94606c3d21df409223465 Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Tue, 2 May 2023 10:01:47 +0200 Subject: moved source directories into `/src` (#264) * moved source directories into `/src` * updated bundle.lua for new `src` path * moved some docs, icon * removed old test trees --- src/zencore/timer.cpp | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 src/zencore/timer.cpp (limited to 'src/zencore/timer.cpp') diff --git a/src/zencore/timer.cpp b/src/zencore/timer.cpp new file mode 100644 index 000000000..1655e912d --- /dev/null +++ b/src/zencore/timer.cpp @@ -0,0 +1,105 @@ +// Copyright Epic Games, Inc. All Rights Reserved. + +#include +#include + +#include + +#if ZEN_PLATFORM_WINDOWS +# include +#elif ZEN_PLATFORM_LINUX +# include +# include +#endif + +namespace zen { + +uint64_t +GetHifreqTimerValue() +{ + uint64_t Timestamp; + +#if ZEN_PLATFORM_WINDOWS + LARGE_INTEGER li; + QueryPerformanceCounter(&li); + + Timestamp = li.QuadPart; +#else + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + Timestamp = (uint64_t(ts.tv_sec) * 1000000ull) + (uint64_t(ts.tv_nsec) / 1000ull); +#endif + + return Timestamp; +} + +uint64_t +InternalGetHifreqTimerFrequency() +{ +#if ZEN_PLATFORM_WINDOWS + LARGE_INTEGER li; + QueryPerformanceFrequency(&li); + + return li.QuadPart; +#else + return 1000000ull; +#endif +} + +uint64_t QpcFreq = InternalGetHifreqTimerFrequency(); +static const double QpcFactor = 1.0 / InternalGetHifreqTimerFrequency(); + +uint64_t +GetHifreqTimerFrequency() +{ + return QpcFreq; +} + +double +GetHifreqTimerToSeconds() +{ + return QpcFactor; +} + +uint64_t +GetHifreqTimerFrequencySafe() +{ + if (!QpcFreq) + { + QpcFreq = InternalGetHifreqTimerFrequency(); + } + + return QpcFreq; +} + +////////////////////////////////////////////////////////////////////////// + +uint64_t detail::g_LofreqTimerValue = GetHifreqTimerValue(); + +void +UpdateLofreqTimerValue() +{ + detail::g_LofreqTimerValue = GetHifreqTimerValue(); +} + +uint64_t +GetLofreqTimerFrequency() +{ + return GetHifreqTimerFrequencySafe(); +} + +////////////////////////////////////////////////////////////////////////// +// +// Testing related code follows... +// + +#if ZEN_WITH_TESTS + +void +timer_forcelink() +{ +} + +#endif + +} // namespace zen -- cgit v1.2.3