0 | module System.Linux.Eventfd
 1 |
 2 | import System.Linux.Eventfd.Prim as P
 3 |
 4 | import public Data.C.Ptr
 5 | import public System.Linux.Eventfd.Eventfd
 6 | import public System.Linux.Eventfd.Flags
 7 | import public System.Posix.File
 8 |
 9 | %default total
10 |
11 | --------------------------------------------------------------------------------
12 | -- API
13 | --------------------------------------------------------------------------------
14 |
15 | ||| Opens a new `eventfd` file descriptor writing the given value
16 | ||| to it.
17 | |||
18 | ||| Notes:
19 | ||| * An `eventfd` should be closed using `close` just like other file
20 | |||   descriptors.
21 | ||| * In general, use `readEventfd` instead of the `read` functions
22 | |||   from `System.Posix.File` to read from an `eventfd`.
23 | ||| * Likewise, use `writeEventfd` instead of `System.Posix.File.write`
24 | export %inline
25 | eventfd : Has Errno es => EIO1 f => (init : Bits64) -> EventfdFlags -> f es Eventfd
26 | eventfd init fs = elift1 (P.eventfd init fs)
27 |
28 | ||| Writes a value to the given event file descriptor.
29 | export %inline
30 | writeEventfd : Has Errno es => EIO1 f => Eventfd -> Bits64 -> f es ()
31 | writeEventfd fd v = elift1 (P.writeEventfd fd v)
32 |
33 | ||| Reads the current value from an event file descriptor.
34 | |||
35 | ||| If the current value is 0, this will block until a non-zero value
36 | ||| is ready. If opened with the `EFD_NONBLOCK` flag, this fails with `EAGAIN`
37 | ||| if no value is ready. If opened with the `EFD_SEMAPHORE` flag, this will
38 | ||| return 1 if a value is ready and reduce the value by 1.
39 | export %inline
40 | readEventfd : Has Errno es => EIO1 f => Eventfd -> f es Bits64
41 | readEventfd fd = elift1 (P.readEventfd fd)
42 |