Commit 48d4e5a1 authored by Mart Lubbers's avatar Mart Lubbers

Add subsecond walltime to windows

parent 980806ed
Pipeline #8819 passed with stage
in 1 minute and 35 seconds
......@@ -14,3 +14,4 @@ PeekNamedPipe@24
SetHandleInformation@12
TerminateProcess@8
GetFullPathNameA@16
GetSystemTimeAsFileTime@4
......@@ -88,3 +88,9 @@ toGmTime :: !Timestamp -> Tm
derefTm :: !Int -> Tm
packTm :: !Tm -> {#Int}
gmTimeC :: !{#Int} -> Int
/**
* Get subsecond precision time
*/
nsTime :: !*World -> (!Timespec, !*World)
:: Timespec = {tv_sec :: !Int, tv_nsec :: !Int}
......@@ -2,6 +2,10 @@ implementation module System.Time
import StdString, StdArray, StdClass, StdOverloaded, StdInt, StdMisc
import System._Pointer
import System._WinBase
import Data.Integer
import Data.List
from Data.Func import $
import Text
import code from library "msvcrt.txt"
......@@ -159,3 +163,20 @@ packTm32 tm = { tm.sec
, tm.yday
, tm.isdst
}
//Number of ticks difference between the windows and linux epoch
TICKSDIFF :== {integer_s=0,integer_a={-1240428288,2}} * TICKSPERSEC
//Number of ticks per second on windows machines
TICKSPERSEC :== {integer_s=10000000,integer_a={}}
BIGTWO :== {integer_s=2,integer_a={}}
nsTime :: !*World -> (!Timespec, !*World)
nsTime w
# (is, w) = GetSystemTimeAsFileTime (createArray 2 0) w
# ticks = uintToInt is.[0] + foldr ($) (uintToInt is.[1]) (repeatn 32 ((*) BIGTWO)) - TICKSDIFF
= ({Timespec | tv_sec=toInt (ticks / TICKSPERSEC), tv_nsec=toInt (ticks rem TICKSPERSEC) *100}, w)
uintToInt :: Int -> Integer
uintToInt i
| i < 0 = toInteger i + {integer_s=0,integer_a={0,1}}
= toInteger i
......@@ -194,3 +194,5 @@ sleep :: !DWORD !*w -> *w
createPipe :: !PHANDLE !PHANDLE !SECURITY_ATTRIBUTES !DWORD !*w -> (!Bool, !*w)
peekNamedPipe :: !HANDLE !LPVOID !DWORD !LPDWORD !LPDWORD !LPDWORD !*w -> (!Bool, !*w)
GetSystemTimeAsFileTime :: !{#Int} !*World -> (!{#Int},!*World)
......@@ -284,3 +284,11 @@ peekNamedPipe :: !HANDLE !LPVOID !DWORD !LPDWORD !LPDWORD !LPDWORD !*w -> (!Bool
peekNamedPipe hNamedPipe lpBuffer nBufferSize lpBytesRead lpTotalBytesAvail lpBytesLeftThisMessage world = code {
ccall PeekNamedPipe@24 "PIpIppp:I:I"
}
GetSystemTimeAsFileTime :: !{#Int} !*World -> (!{#Int},!*World)
GetSystemTimeAsFileTime i w
= code {
push_a 0
ccall GetSystemTimeAsFileTime@4 "PA:I:AA"
pop_b 1
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment