Skip to content

Commit

Permalink
[std/times]getTime now uses high resolution API on windows (#17901)
Browse files Browse the repository at this point in the history
  • Loading branch information
ringabout authored Jun 23, 2021
1 parent 63456c6 commit 496bd79
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/pure/times.nim
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,7 @@ since((1, 1)):
export fromUnixFloat
export toUnixFloat


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 +913,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 +2596,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
3 changes: 3 additions & 0 deletions lib/windows/winlean.nim
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,9 @@ proc getProcessTimes*(hProcess: Handle; lpCreationTime, lpExitTime,
lpKernelTime, lpUserTime: var FILETIME): WINBOOL {.stdcall,
dynlib: "kernel32", importc: "GetProcessTimes".}

proc getSystemTimePreciseAsFileTime*(lpSystemTimeAsFileTime: var FILETIME) {.
importc: "GetSystemTimePreciseAsFileTime", dynlib: "kernel32", stdcall, sideEffect.}

type inet_ntop_proc = proc(family: cint, paddr: pointer, pStringBuffer: cstring,
stringBufSize: int32): cstring {.gcsafe, stdcall, tags: [].}

Expand Down

0 comments on commit 496bd79

Please sign in to comment.