Commit 980806ed authored by Mart Lubbers's avatar Mart Lubbers

add subsecond timestamping for linux and Mac os

parent 0ce751c4
Pipeline #8805 passed with stage
in 1 minute and 29 seconds
......@@ -76,9 +76,11 @@ write :: !Int !{#Char} !Int !*w -> (!Int, !*w)
select_ :: !Int !Pointer !Pointer !Pointer !Pointer !*w -> (!Int, !*w)
kill :: !Int !Int !*w -> (!Int, !*w)
timegm :: !{#Int} -> Int
clock_gettime :: !Int !Pointer !*w -> (!Int, !*w)
//Memory (impure)
malloc :: !Int -> Pointer
mallocSt :: !Int !*w -> (!Pointer, !*w)
free :: !Pointer -> Int
freeSt :: !Pointer !*w -> *w
memcpy_string_to_pointer :: !Pointer !{#Char} !Int -> Pointer
......
......@@ -164,6 +164,10 @@ malloc :: !Int -> Pointer
malloc num = code {
ccall malloc "I:p"
}
mallocSt :: !Int !*w -> (!Pointer, !*w)
mallocSt num w = code {
ccall malloc "I:p:A"
}
free :: !Pointer -> Int
free ptr = code {
ccall free "p:I"
......@@ -176,6 +180,10 @@ memcpy_string_to_pointer :: !Pointer !{#Char} !Int -> Pointer
memcpy_string_to_pointer p s n = code {
ccall memcpy "psp:p"
}
clock_gettime :: !Int !Pointer !*w -> (!Int, !*w)
clock_gettime _ _ _ = code {
ccall clock_gettime "Ip:I:A"
}
//Mapping to/from byte arrays
unpackStat :: !{#Char} -> Stat
......
......@@ -75,9 +75,11 @@ write :: !Int !{#Char} !Int !*w -> (!Int, !*w)
select_ :: !Int !Pointer !Pointer !Pointer !Pointer !*w -> (!Int, !*w)
kill :: !Int !Int !*w -> (!Int, !*w)
timegm :: !{#Int} -> Int
clock_gettime :: !Int !Pointer !*w -> (!Int, !*w)
//Memory (impure)
malloc :: !Int -> Pointer
mallocSt :: !Int !*w -> (!Pointer, !*w)
free :: !Pointer -> Int
freeSt :: !Pointer !*w -> *w
memcpy_string_to_pointer :: !Pointer !{#Char} !Int -> Pointer
......
......@@ -165,6 +165,10 @@ malloc :: !Int -> Pointer
malloc num = code {
ccall malloc "I:p"
}
mallocSt :: !Int !*w -> (!Pointer, !*w)
mallocSt num w = code {
ccall malloc "I:p:A"
}
free :: !Pointer -> Int
free ptr = code {
ccall free "p:I"
......@@ -177,6 +181,10 @@ memcpy_string_to_pointer :: !Pointer !{#Char} !Int -> Pointer
memcpy_string_to_pointer p s n = code {
ccall memcpy "psp:p"
}
clock_gettime :: !Int !Pointer !*w -> (!Int, !*w)
clock_gettime _ _ _ = code {
ccall clock_gettime "Ip:I:A"
}
//Mapping to/from byte arrays
unpackStat :: !{#Char} -> Stat
......
......@@ -85,3 +85,8 @@ toLocalTime :: !Timestamp !*World -> (!Tm,!*World)
* Convert a timestamp to a Tm record (GMT time)
*/
toGmTime :: !Timestamp -> Tm
/**
* Get subsecond precision time
*/
nsTime :: !*World -> (!Timespec, !*World)
:: Timespec = {tv_sec :: !Int, tv_nsec :: !Int}
......@@ -166,3 +166,13 @@ unpackTm buf off =
sizeOfTm :: Int
sizeOfTm = 36
nsTime :: !*World -> (!Timespec, !*World)
nsTime w
# (p, w) = mallocSt 16 w
# (r, w) = clock_gettime 0 p w
= derefTimespec p w
//Include world to force evaluation order...
derefTimespec :: !Pointer !*w -> (!Timespec, !*w)
derefTimespec p w = ({Timespec | tv_sec = readInt p 0, tv_nsec = readInt p 8}, w)
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