mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
33 lines
1.1 KiB
C
33 lines
1.1 KiB
C
module std::time::os;
|
|
import std::os::win32;
|
|
|
|
$if (env::os_is_win32() && env::COMPILER_LIBC_AVAILABLE)
|
|
|
|
extern fn void win32_GetSystemTimeAsFileTime(Win32_FILETIME* time) @extern("GetSystemTimeAsFileTime");
|
|
extern fn Win32_BOOL win32_QueryPerformanceFrequency(Win32_LARGE_INTEGER* lpFrequency) @extern("QueryPerformanceFrequency");
|
|
extern fn Win32_BOOL win32_QueryPerformanceCounter(Win32_LARGE_INTEGER* lpPerformanceCount) @extern("QueryPerformanceCounter");
|
|
|
|
const ulong WINDOWS_TICK_US @local = 10;
|
|
const ulong WIN_TO_UNIX_EPOCH_US @local = 116444736000000000u64 / WINDOWS_TICK_US;
|
|
|
|
fn Clock native_clock()
|
|
{
|
|
static Win32_LARGE_INTEGER freq;
|
|
if (!freq.quadPart)
|
|
{
|
|
if (!win32_QueryPerformanceFrequency(&freq)) return 0;
|
|
}
|
|
Win32_LARGE_INTEGER counter @noinit;
|
|
if (!win32_QueryPerformanceCounter(&counter)) return 0;
|
|
return (Clock)counter.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);
|
|
}
|
|
|
|
$endif |