diff --git a/src/libraries/OS-Posix/System/Time.icl b/src/libraries/OS-Posix/System/Time.icl index 05494948e1a76ef8186a221875810e65ffe82b38..c982af4055865959e6cd38ad1eb370c70c94869b 100644 --- a/src/libraries/OS-Posix/System/Time.icl +++ b/src/libraries/OS-Posix/System/Time.icl @@ -172,7 +172,7 @@ nsTime w # (p, w) = mallocSt 16 w # (r, w) = clock_gettime 0 p w //For completeness sake -| r == -1 = abort "clock_gettime error: everyone should have permission to open CLOCK_REALTIME?" +| r <> 0 = abort "clock_gettime error: everyone should have permission to open CLOCK_REALTIME?" # (tv_sec, p) = readIntP p 0 # (tv_nsec, p) = readIntP p 8 = ({Timespec | tv_sec = tv_sec, tv_nsec = tv_nsec}, freeSt p w) diff --git a/src/libraries/OS-Windows/Clean System Files/_WinBase_library b/src/libraries/OS-Windows/Clean System Files/_WinBase_library index f5e747c2eee4f9412b0932f9b9de6ea9c38c1515..d967da4a4f0c5c3aa399412d1c479db051658e61 100644 --- a/src/libraries/OS-Windows/Clean System Files/_WinBase_library +++ b/src/libraries/OS-Windows/Clean System Files/_WinBase_library @@ -14,3 +14,4 @@ PeekNamedPipe@24 SetHandleInformation@12 TerminateProcess@8 GetFullPathNameA@16 +GetSystemTimeAsFileTime@4 diff --git a/src/libraries/OS-Windows/System/Time.dcl b/src/libraries/OS-Windows/System/Time.dcl index 5dba675ff4096b7538a421712f5c979aeffd1fba..525c8b6f575b2f9c077fb4be9768c57566904aef 100644 --- a/src/libraries/OS-Windows/System/Time.dcl +++ b/src/libraries/OS-Windows/System/Time.dcl @@ -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} diff --git a/src/libraries/OS-Windows/System/Time.icl b/src/libraries/OS-Windows/System/Time.icl index 1b5084068486c8683e0e542ab1ed290548b7950e..705c34d1b2381381d2e158f8e953afbb846a6a83 100644 --- a/src/libraries/OS-Windows/System/Time.icl +++ b/src/libraries/OS-Windows/System/Time.icl @@ -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 diff --git a/src/libraries/OS-Windows/System/_WinBase.dcl b/src/libraries/OS-Windows/System/_WinBase.dcl index 74866294f4600dc5e4d5093378b50e990f69c6d9..bdc3dfe23a163a1391da575b970722b538ecdad0 100644 --- a/src/libraries/OS-Windows/System/_WinBase.dcl +++ b/src/libraries/OS-Windows/System/_WinBase.dcl @@ -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) diff --git a/src/libraries/OS-Windows/System/_WinBase.icl b/src/libraries/OS-Windows/System/_WinBase.icl index 02173d319741b9e867925bbcef58ae42829c746f..ac8f3c27804b73db541ddb6d004fa724feb14d49 100644 --- a/src/libraries/OS-Windows/System/_WinBase.icl +++ b/src/libraries/OS-Windows/System/_WinBase.icl @@ -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