forked from ish-app/ish
-
Notifications
You must be signed in to change notification settings - Fork 11
/
poll.h
67 lines (60 loc) · 1.82 KB
/
poll.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#ifndef FS_POLL_H
#define FS_POLL_H
#include "kernel/fs.h"
struct real_poll {
int fd;
};
struct poll {
struct list poll_fds;
struct real_poll real;
int notify_pipe[2];
int waiters; // if nonzero, notify_pipe exists
lock_t lock;
};
struct poll_fd {
// locked by containing struct poll
struct fd *fd;
struct list fds;
int types;
union poll_fd_info {
void *ptr;
int fd;
uint64_t num;
} info;
// locked by containing struct fd
struct poll *poll;
struct list polls;
};
// these are defined in system headers somewhere
#undef POLL_IN
#undef POLL_OUT
#undef POLL_MSG
#undef POLL_ERR
#undef POLL_PRI
#undef POLL_HUP
#define POLL_READ 1
#define POLL_PRI 2
#define POLL_WRITE 4
#define POLL_ERR 8
#define POLL_HUP 16
#define POLL_NVAL 32
#define POLL_ONESHOT (1 << 30)
struct poll_event {
struct fd *fd;
int types;
};
struct poll *poll_create(void);
bool poll_has_fd(struct poll *poll, struct fd *fd);
int poll_add_fd(struct poll *poll, struct fd *fd, int types, union poll_fd_info info);
int poll_mod_fd(struct poll *poll, struct fd *fd, int types, union poll_fd_info info);
int poll_del_fd(struct poll *poll, struct fd *fd);
// please do not call this while holding any locks you would acquire in your poll operation
void poll_wakeup(struct fd *fd);
// Waits for events on the fds in this poll, and calls the callback for each one found.
// Returns the number of times the callback returned 1, or negative for error.
typedef int (*poll_callback_t)(void *context, int types, union poll_fd_info info);
int poll_wait(struct poll *poll, poll_callback_t callback, void *context, struct timespec *timeout);
// does not lock the poll because lock ordering, you must ensure no other
// thread will add or remove fds from this poll
void poll_destroy(struct poll *poll);
#endif