...
 
Commits (1)
...@@ -77,6 +77,7 @@ select_ :: !Int !Pointer !Pointer !Pointer !Pointer !*w -> (!Int, !*w) ...@@ -77,6 +77,7 @@ select_ :: !Int !Pointer !Pointer !Pointer !Pointer !*w -> (!Int, !*w)
kill :: !Int !Int !*w -> (!Int, !*w) kill :: !Int !Int !*w -> (!Int, !*w)
timegm :: !{#Int} -> Int timegm :: !{#Int} -> Int
clock_gettime :: !Int !Pointer !*w -> (!Int, !*w) clock_gettime :: !Int !Pointer !*w -> (!Int, !*w)
nanosleep :: !Pointer !Pointer !*w -> (!Int, !*w)
//Memory (impure) //Memory (impure)
malloc :: !Int -> Pointer malloc :: !Int -> Pointer
......
...@@ -184,6 +184,10 @@ clock_gettime :: !Int !Pointer !*w -> (!Int, !*w) ...@@ -184,6 +184,10 @@ clock_gettime :: !Int !Pointer !*w -> (!Int, !*w)
clock_gettime _ _ _ = code { clock_gettime _ _ _ = code {
ccall clock_gettime "Ip:I:A" ccall clock_gettime "Ip:I:A"
} }
nanosleep :: !Pointer !Pointer !*w -> (!Int, !*w)
nanosleep _ _ _ = code {
ccall nanosleep "pp:I:A"
}
//Mapping to/from byte arrays //Mapping to/from byte arrays
unpackStat :: !{#Char} -> Stat unpackStat :: !{#Char} -> Stat
......
...@@ -76,6 +76,7 @@ select_ :: !Int !Pointer !Pointer !Pointer !Pointer !*w -> (!Int, !*w) ...@@ -76,6 +76,7 @@ select_ :: !Int !Pointer !Pointer !Pointer !Pointer !*w -> (!Int, !*w)
kill :: !Int !Int !*w -> (!Int, !*w) kill :: !Int !Int !*w -> (!Int, !*w)
timegm :: !{#Int} -> Int timegm :: !{#Int} -> Int
clock_gettime :: !Int !Pointer !*w -> (!Int, !*w) clock_gettime :: !Int !Pointer !*w -> (!Int, !*w)
nanosleep :: !Pointer !Pointer !*w -> (!Int, !*w)
//Memory (impure) //Memory (impure)
malloc :: !Int -> Pointer malloc :: !Int -> Pointer
......
...@@ -185,6 +185,10 @@ clock_gettime :: !Int !Pointer !*w -> (!Int, !*w) ...@@ -185,6 +185,10 @@ clock_gettime :: !Int !Pointer !*w -> (!Int, !*w)
clock_gettime _ _ _ = code { clock_gettime _ _ _ = code {
ccall clock_gettime "Ip:I:A" ccall clock_gettime "Ip:I:A"
} }
nanosleep :: !Pointer !Pointer !*w -> (!Int, !*w)
nanosleep _ _ _ = code {
ccall nanosleep "pp:I:A"
}
//Mapping to/from byte arrays //Mapping to/from byte arrays
unpackStat :: !{#Char} -> Stat unpackStat :: !{#Char} -> Stat
......
...@@ -98,3 +98,8 @@ instance < Timespec ...@@ -98,3 +98,8 @@ instance < Timespec
instance + Timespec instance + Timespec
instance - Timespec instance - Timespec
instance zero Timespec instance zero Timespec
/*
* Sleep for the given time
*/
nanoSleep :: !Timespec !*w -> *w
...@@ -206,3 +206,12 @@ where ...@@ -206,3 +206,12 @@ where
instance zero Timespec instance zero Timespec
where zero = {tv_sec=0, tv_nsec=0} where zero = {tv_sec=0, tv_nsec=0}
nanoSleep :: !Timespec !*w -> *w
nanoSleep ts w
# (p, w) = mallocSt 16 w
# p = writeInt p 0 ts.tv_sec
# p = writeInt p 8 ts.tv_nsec
# (res, w) = nanosleep p 0 w
| res <> 0 = abort "nanosleep error: did I just got interrupted?"
= freeSt p w
...@@ -103,3 +103,8 @@ instance < Timespec ...@@ -103,3 +103,8 @@ instance < Timespec
instance + Timespec instance + Timespec
instance - Timespec instance - Timespec
instance zero Timespec instance zero Timespec
/**
* Sleep the given time, note that there is only millisecond precision sleeping
*/
nanoSleep :: !Timespec !*w -> *w
...@@ -210,3 +210,8 @@ where ...@@ -210,3 +210,8 @@ where
instance zero Timespec instance zero Timespec
where zero = {tv_sec=0, tv_nsec=0} where zero = {tv_sec=0, tv_nsec=0}
nanoSleep :: !Timespec !*w -> *w
nanoSleep ts w
# ms = ts.tv_sec*1000+ts.tv_nsec/1000
= sleep ms w