feat: IO polling for file descriptor
[lunaix-os.git] / lunaix-os / includes / lunaix / iopoll.h
1 #ifndef __LUNAIX_IOPOLL_H
2 #define __LUNAIX_IOPOLL_H
3
4 #include <lunaix/device.h>
5 #include <lunaix/ds/llist.h>
6 #include <lunaix/fs.h>
7
8 #include <usr/lunaix/poll.h>
9
10 typedef struct llist_header poll_evt_q;
11
12 struct poll_opts
13 {
14     struct pollfd** upoll;
15     int upoll_num;
16     int timeout;
17 };
18
19 struct iopoller
20 {
21     poll_evt_q evt_listener;
22     struct v_file* file_ref;
23     pid_t pid;
24 };
25
26 struct iopoll
27 {
28     struct iopoller** pollers;
29     int n_poller;
30 };
31
32 static inline void
33 iopoll_listen_on(struct iopoller* listener, poll_evt_q* source)
34 {
35     llist_append(source, &listener->evt_listener);
36 }
37
38 void
39 iopoll_wake_pollers(poll_evt_q*);
40
41 void
42 iopoll_init(struct iopoll*);
43
44 void
45 iopoll_free(pid_t, struct iopoll*);
46
47 int
48 iopoll_install(pid_t, struct iopoll*, struct v_fd*);
49
50 int
51 iopoll_remove(pid_t, struct iopoll*, int);
52
53 static inline void
54 poll_setrevt(struct poll_info* pinfo, int evt)
55 {
56     pinfo->revents = (pinfo->revents & ~evt) | evt;
57 }
58
59 static inline int
60 poll_checkevt(struct poll_info* pinfo, int evt)
61 {
62     return pinfo->events & evt;
63 }
64
65 #endif /* __LUNAIX_POLL_H */