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