20 struct timespec timeout = { 0, 0 };
21 struct kevent ev = {};
30 EV_SET(&ev, SIGCHLD, EVFILT_SIGNAL, EV_ADD, 0, 0, 0);
31 kevent(
poll_fd, &ev, 1, NULL, 0, &timeout);
37 static uint16_t
get_flags(
unsigned int flags,
unsigned int mask)
55 struct timespec timeout = { 0, 0 };
62 if (flags & ULOOP_EDGE_DEFER)
65 changed = flags ^
fd->flags;
74 EV_SET(&ev[nev++],
fd->fd, EVFILT_READ, kflags, 0, 0,
fd);
79 EV_SET(&ev[nev++],
fd->fd, EVFILT_WRITE, kflags, 0, 0,
fd);
85 if (kevent(
poll_fd, ev, nev, NULL, fl, &timeout) == -1)
94 flags |= ULOOP_EDGE_DEFER;
96 flags &= ~ULOOP_EDGE_DEFER;
108 #ifdef CLOCK_MONOTONIC
109 struct timespec ts = { 0, 0 };
111 clock_gettime(CLOCK_MONOTONIC, &ts);
113 return ts.tv_sec * 1000000 + ts.tv_nsec / 1000;
115 struct timeval tv = { 0, 0 };
117 gettimeofday(&tv, NULL);
119 return tv.tv_sec * 1000000 + tv.tv_usec;
129 ts.tv_sec = timeout / 1000;
130 ts.tv_nsec = (timeout % 1000) * 1000000;
134 for (n = 0; n < nfds; n++) {
135 if (
events[n].filter == EVFILT_TIMER) {
159 if(
events[n].filter == EVFILT_READ)
161 else if (
events[n].filter == EVFILT_WRITE)
170 if (u->
flags & ULOOP_EDGE_DEFER) {
171 u->
flags &= ~ULOOP_EDGE_DEFER;
186 EV_SET(&ev, (uintptr_t)tm, EVFILT_TIMER, EV_ADD, NOTE_USECONDS, msecs * 1000, tm);
188 return kevent(
poll_fd, &ev, 1, NULL, 0, NULL);
195 EV_SET(&ev, (uintptr_t)tm, EVFILT_TIMER, EV_DELETE, 0, 0, NULL);
197 return kevent(
poll_fd, &ev, 1, NULL, 0, NULL);
208 return (t1 - t2) / 1000;
union uloop_interval::@15 priv
uloop_interval_handler cb
struct uloop_interval::@15::@16 time
static uint16_t get_flags(unsigned int flags, unsigned int mask)
static int register_poll(struct uloop_fd *fd, unsigned int flags)
static int uloop_fetch_events(int timeout)
static int uloop_init_pollfd(void)
static int timer_register(struct uloop_interval *tm, unsigned int msecs)
static int timer_remove(struct uloop_interval *tm)
static struct kevent events[ULOOP_MAX_EVENTS]
static int register_kevent(struct uloop_fd *fd, unsigned int flags)
static int64_t get_timestamp_us(void)
static int __uloop_fd_delete(struct uloop_fd *fd)
static int64_t timer_next(struct uloop_interval *tm)
int uloop_fd_delete(struct uloop_fd *fd)
static struct uloop_fd_event cur_fds[10]
#define ULOOP_EDGE_TRIGGER