Files
c3c/lib/std/time/os/time_win32.c3
Christoffer Lerno abe4727c3a Deprecate uXX and iXX bit suffixes.
Add experimental LL / ULL suffixes for int128 and uint128 literals.
2025-05-13 23:48:59 +02:00

28 lines
786 B
Plaintext

module std::time::os @if(env::WIN32);
import std::os::win32;
import std::math;
const ulong WINDOWS_TICK_US @local = 10;
const ulong WIN_TO_UNIX_EPOCH_US @local = 116444736000000000UL / WINDOWS_TICK_US;
fn Clock native_clock()
{
static Win32_LARGE_INTEGER freq;
static ulong div = 0;
ulong mult = 0;
if (!freq.quadPart)
{
if (!win32::queryPerformanceFrequency(&freq)) return 0;
}
Win32_LARGE_INTEGER counter @noinit;
if (!win32::queryPerformanceCounter(&counter)) return 0;
return (Clock)counter.quadPart.muldiv(1_000_000_000, freq.quadPart);
}
fn Time native_timestamp()
{
Win32_FILETIME ft @noinit;
win32::getSystemTimeAsFileTime(&ft);
ulong result = (ulong)ft.dwHighDateTime << 32 | ft.dwLowDateTime;
return (Time)(result / WINDOWS_TICK_US - WIN_TO_UNIX_EPOCH_US);
}