diff options
| author | Stefan Boberg <[email protected]> | 2023-05-02 10:01:47 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-05-02 10:01:47 +0200 |
| commit | 075d17f8ada47e990fe94606c3d21df409223465 (patch) | |
| tree | e50549b766a2f3c354798a54ff73404217b4c9af /src/zencore/timer.cpp | |
| parent | fix: bundle shouldn't append content zip to zen (diff) | |
| download | zen-075d17f8ada47e990fe94606c3d21df409223465.tar.xz zen-075d17f8ada47e990fe94606c3d21df409223465.zip | |
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
Diffstat (limited to 'src/zencore/timer.cpp')
| -rw-r--r-- | src/zencore/timer.cpp | 105 |
1 files changed, 105 insertions, 0 deletions
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 <zencore/thread.h> +#include <zencore/timer.h> + +#include <zencore/testing.h> + +#if ZEN_PLATFORM_WINDOWS +# include <zencore/windows.h> +#elif ZEN_PLATFORM_LINUX +# include <time.h> +# include <unistd.h> +#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 |