Decoupling Architectural-specific Code (#35)
[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
7 #include <usr/lunaix/poll.h>
8
9 struct thread;  // <lunaix/process.h>
10 struct proc_info;  // <lunaix/process.h>
11 struct v_fd;    // <lunaix/fs.h>
12
13 typedef struct llist_header poll_evt_q;
14
15 struct poll_opts
16 {
17     struct pollfd** upoll;
18     int upoll_num;
19     int timeout;
20 };
21
22 struct iopoller
23 {
24     poll_evt_q evt_listener;
25     struct v_file* file_ref;
26     struct thread* thread;
27 };
28
29 struct iopoll
30 {
31     struct iopoller** pollers;
32     int n_poller;
33 };
34
35 static inline void
36 iopoll_listen_on(struct iopoller* listener, poll_evt_q* source)
37 {
38     llist_append(source, &listener->evt_listener);
39 }
40
41 static inline void
42 iopoll_init_evt_q(poll_evt_q* source)
43 {
44     llist_init_head(source);
45 }
46
47 void
48 iopoll_wake_pollers(poll_evt_q*);
49
50 void
51 iopoll_init(struct iopoll*);
52
53 void
54 iopoll_free(struct proc_info*);
55
56 int
57 iopoll_install(struct thread* thread, struct v_fd* fd);
58
59 int
60 iopoll_remove(struct thread*, int);
61
62 static inline void
63 poll_setrevt(struct poll_info* pinfo, int evt)
64 {
65     pinfo->revents = (pinfo->revents & ~evt) | evt;
66 }
67
68 static inline int
69 poll_checkevt(struct poll_info* pinfo, int evt)
70 {
71     return pinfo->events & evt;
72 }
73
74 #endif /* __LUNAIX_POLL_H */