time_windows.odin 778 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package time
  2. import win32 "core:sys/windows"
  3. IS_SUPPORTED :: true
  4. now :: proc() -> Time {
  5. file_time: win32.FILETIME
  6. win32.GetSystemTimeAsFileTime(&file_time)
  7. ns := win32.FILETIME_as_unix_nanoseconds(file_time)
  8. return Time{_nsec=ns}
  9. }
  10. sleep :: proc(d: Duration) {
  11. win32.Sleep(win32.DWORD(d/Millisecond))
  12. }
  13. _tick_now :: proc "contextless" () -> Tick {
  14. mul_div_u64 :: proc "contextless" (val, num, den: i64) -> i64 {
  15. q := val / den
  16. r := val % den
  17. return q * num + r * num / den
  18. }
  19. @thread_local qpc_frequency: win32.LARGE_INTEGER
  20. if qpc_frequency == 0 {
  21. win32.QueryPerformanceFrequency(&qpc_frequency)
  22. }
  23. now: win32.LARGE_INTEGER
  24. win32.QueryPerformanceCounter(&now)
  25. _nsec := mul_div_u64(i64(now), 1e9, i64(qpc_frequency))
  26. return Tick{_nsec = _nsec}
  27. }