0 | module System.Posix.Timer.Prim
4 | import public Data.C.Integer
5 | import public System.Posix.Errno
6 | import public System.Posix.Timer.Types
7 | import public System.Posix.Time
15 | %foreign "C:li_setitimer, posix-idris"
16 | prim__setitimer : Bits8 -> AnyPtr -> AnyPtr -> PrimIO CInt
18 | %foreign "C:li_setitimer1, posix-idris"
19 | prim__setitimer1 : Bits8 -> TimeT -> SusecondsT -> TimeT -> SusecondsT -> PrimIO CInt
21 | %foreign "C:getitimer, posix-idris"
22 | prim__getitimer : Bits8 -> AnyPtr -> PrimIO ()
24 | %foreign "C:li_clock_gettime, posix-idris"
25 | prim__clock_gettime : Bits8 -> AnyPtr -> PrimIO CInt
27 | %foreign "C:li_clock_getres, posix-idris"
28 | prim__clock_getres : Bits8 -> AnyPtr -> PrimIO CInt
30 | %foreign "C:li_nanosleep, posix-idris"
31 | prim__nanosleep : AnyPtr -> AnyPtr -> PrimIO CInt
33 | %foreign "C:li_nanosleep1, posix-idris"
34 | prim__nanosleep1 : TimeT -> NsecT -> PrimIO CInt
36 | %foreign "C:li_clock_nanosleep, posix-idris"
37 | prim__clock_nanosleep : Bits8 -> AnyPtr -> AnyPtr -> PrimIO Bits32
39 | %foreign "C:li_clock_nanosleep_abs, posix-idris"
40 | prim__clock_nanosleep_abs : Bits8 -> AnyPtr -> PrimIO Bits32
50 | export %foreign "C:clock, posix-idris"
51 | clock : PrimIO ClockT
66 | setitimer : Which -> (new,old : IOTimerval) -> EPrim ()
67 | setitimer w n o = toUnit $
prim__setitimer (whichCode w) (unwrap n) (unwrap o)
71 | getitimer : Which -> (old : IOTimerval) -> PrimIO ()
72 | getitimer w o = prim__getitimer (whichCode w) (unwrap o)
80 | export %foreign "C:alarm, posix-idris"
81 | alarm : UInt -> PrimIO UInt
86 | clockGetTime : ClockId -> IOTimespec -> EPrim ()
87 | clockGetTime c t = toUnit $
prim__clock_gettime (clockCode c) (unwrap t)
92 | clockGetRes : ClockId -> IOTimespec -> EPrim ()
93 | clockGetRes c t = toUnit $
prim__clock_getres (clockCode c) (unwrap t)
100 | nanosleep_ : (dur,rem : IOTimespec) -> EPrim ()
101 | nanosleep_ d r = toUnit $
prim__nanosleep (unwrap d) (unwrap r)
105 | clockNanosleep : ClockId -> (dur,rem : IOTimespec) -> EPrim ()
106 | clockNanosleep c d r =
107 | posToUnit $
prim__clock_nanosleep (clockCode c) (unwrap d) (unwrap r)
114 | clockNanosleepAbs : ClockId -> (time : IOTimespec) -> EPrim ()
115 | clockNanosleepAbs c d =
116 | posToUnit $
prim__clock_nanosleep_abs (clockCode c) (unwrap d)
123 | ClockTpe : ClockId -> ClockType
124 | ClockTpe CLOCK_REALTIME = UTC
125 | ClockTpe CLOCK_MONOTONIC = Monotonic
126 | ClockTpe CLOCK_PROCESS_CPUTIME_ID = Process
127 | ClockTpe CLOCK_THREAD_CPUTIME_ID = Thread
130 | IClock : ClockId -> Type
131 | IClock = Clock . ClockTpe
135 | setTimer : Which -> Timerval -> EPrim ()
136 | setTimer w (TRV (TV si ui) (TV sv uv)) =
137 | toUnit $
prim__setitimer1 (whichCode w) si ui sv uv
141 | getTimer : Which -> EPrim Timerval
143 | withStruct Itimerval $
\str,t =>
144 | let _ # t := toF1 (getitimer wh str) t
145 | r # t := timerval str t
150 | getTime : (c : ClockId) -> EPrim (IClock c)
152 | withStruct STimespec $
\str,t =>
153 | let R _ t := clockGetTime c str t | E x t => E x t
154 | c # t := toClock str t
159 | getResolution : (c : ClockId) -> EPrim (IClock c)
161 | withStruct STimespec $
\str,t =>
162 | let R _ t := clockGetRes c str t | E x t => E x t
163 | c # t := toClock str t
169 | nanosleep : (dur : Clock Monotonic) -> EPrim ()
170 | nanosleep cl = toUnit $
prim__nanosleep1 cl.secs cl.nsecs