summaryrefslogtreecommitdiff
path: root/src/util/timer/timer_windows.c
blob: 4ff95ff711e0f3582c85762676024a43175362ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include "../../winwrap.h"

#include "timer.h"

f64 nn_get_tick(void)
{
    LARGE_INTEGER result;
    QueryPerformanceCounter(&result);
    return result.QuadPart / (f64)performance_frequency.QuadPart;
}

// https://stackoverflow.com/a/46024468
static const s64 UNIX_TIME_START = 0x019DB1DED53E8000; // January 1st, 1970 in "ticks"

u64 nn_get_timestamp(void)
{
    FILETIME ft;
#ifdef NAUNET_WIN32_COMPAT_MODE
    GetSystemTimeAsFileTime(&ft);
#else
    // https://github.com/llvm/llvm-project/commit/3ec634e65a02d5f443cc982e9e00ec4e51143d07
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8 && WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)) || \
    (_WIN32_WINNT >= _WIN32_WINNT_WIN10)
    GetSystemTimePreciseAsFileTime(&ft);
#else
#error "GetSystemTimePreciseAsFileTime() requested but not supported."
#endif
#endif
    return (((LARGE_INTEGER){ .LowPart = ft.dwLowDateTime, .HighPart = ft.dwHighDateTime }).QuadPart - UNIX_TIME_START) / 10u;
}