Commit fa40907d authored by Mart Lubbers's avatar Mart Lubbers

Merge branch 'add-subsecond-time' of...

Merge branch 'add-subsecond-time' of gitlab.science.ru.nl:clean-and-itasks/clean-platform into add-subsecond-time
parents bbe0c239 48d4e5a1
Pipeline #8838 passed with stage
in 1 minute and 28 seconds
...@@ -172,7 +172,7 @@ nsTime w ...@@ -172,7 +172,7 @@ nsTime w
# (p, w) = mallocSt 16 w # (p, w) = mallocSt 16 w
# (r, w) = clock_gettime 0 p w # (r, w) = clock_gettime 0 p w
//For completeness sake //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_sec, p) = readIntP p 0
# (tv_nsec, p) = readIntP p 8 # (tv_nsec, p) = readIntP p 8
= ({Timespec | tv_sec = tv_sec, tv_nsec = tv_nsec}, freeSt p w) = ({Timespec | tv_sec = tv_sec, tv_nsec = tv_nsec}, freeSt p w)
...@@ -14,3 +14,4 @@ PeekNamedPipe@24 ...@@ -14,3 +14,4 @@ PeekNamedPipe@24
SetHandleInformation@12 SetHandleInformation@12
TerminateProcess@8 TerminateProcess@8
GetFullPathNameA@16 GetFullPathNameA@16
GetSystemTimeAsFileTime@4
...@@ -88,3 +88,9 @@ toGmTime :: !Timestamp -> Tm ...@@ -88,3 +88,9 @@ toGmTime :: !Timestamp -> Tm
derefTm :: !Int -> Tm derefTm :: !Int -> Tm
packTm :: !Tm -> {#Int} packTm :: !Tm -> {#Int}
gmTimeC :: !{#Int} -> 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 ...@@ -2,6 +2,10 @@ implementation module System.Time
import StdString, StdArray, StdClass, StdOverloaded, StdInt, StdMisc import StdString, StdArray, StdClass, StdOverloaded, StdInt, StdMisc
import System._Pointer import System._Pointer
import System._WinBase
import Data.Integer
import Data.List
from Data.Func import $
import Text import Text
import code from library "msvcrt.txt" import code from library "msvcrt.txt"
...@@ -159,3 +163,20 @@ packTm32 tm = { tm.sec ...@@ -159,3 +163,20 @@ packTm32 tm = { tm.sec
, tm.yday , tm.yday
, tm.isdst , 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 ...@@ -194,3 +194,5 @@ sleep :: !DWORD !*w -> *w
createPipe :: !PHANDLE !PHANDLE !SECURITY_ATTRIBUTES !DWORD !*w -> (!Bool, !*w) createPipe :: !PHANDLE !PHANDLE !SECURITY_ATTRIBUTES !DWORD !*w -> (!Bool, !*w)
peekNamedPipe :: !HANDLE !LPVOID !DWORD !LPDWORD !LPDWORD !LPDWORD !*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 ...@@ -284,3 +284,11 @@ peekNamedPipe :: !HANDLE !LPVOID !DWORD !LPDWORD !LPDWORD !LPDWORD !*w -> (!Bool
peekNamedPipe hNamedPipe lpBuffer nBufferSize lpBytesRead lpTotalBytesAvail lpBytesLeftThisMessage world = code { peekNamedPipe hNamedPipe lpBuffer nBufferSize lpBytesRead lpTotalBytesAvail lpBytesLeftThisMessage world = code {
ccall PeekNamedPipe@24 "PIpIppp:I:I" 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