Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[std/times]getTime now uses high resolution API on windows #17901

Merged
merged 9 commits into from
Jun 23, 2021
Merged
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/pure/times.nim
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,11 @@ since((1, 1)):
export fromUnixFloat
export toUnixFloat


when defined(windows): # TODO move to winlean
ringabout marked this conversation as resolved.
Show resolved Hide resolved
proc getSystemTimePreciseAsFileTime(lpSystemTimeAsFileTime: var FILETIME) {.
importc: "GetSystemTimePreciseAsFileTime", dynlib: "kernel32", stdcall, sideEffect.}

proc fromWinTime*(win: int64): Time =
## Convert a Windows file time (100-nanosecond intervals since
## `1601-01-01T00:00:00Z`) to a `Time`.
Expand Down Expand Up @@ -912,7 +917,7 @@ proc getTime*(): Time {.tags: [TimeEffect], benign.} =
result = initTime(ts.tv_sec.int64, ts.tv_nsec.int)
elif defined(windows):
var f {.noinit.}: FILETIME
getSystemTimeAsFileTime(f)
getSystemTimePreciseAsFileTime(f)
result = fromWinTime(rdFileTime(f))

proc `-`*(a, b: Time): Duration {.operator, extern: "ntDiffTime".} =
Expand Down Expand Up @@ -2595,7 +2600,7 @@ proc epochTime*(): float {.tags: [TimeEffect].} =
toBiggestFloat(ts.tv_nsec.int64) / 1_000_000_000
elif defined(windows):
var f {.noinit.}: winlean.FILETIME
getSystemTimeAsFileTime(f)
getSystemTimePreciseAsFileTime(f)
var i64 = rdFileTime(f) - epochDiff
var secs = i64 div rateDiff
var subsecs = i64 mod rateDiff
Expand Down