… | |
… | |
202 | #ifndef CLOCK_REALTIME |
202 | #ifndef CLOCK_REALTIME |
203 | # undef EV_USE_REALTIME |
203 | # undef EV_USE_REALTIME |
204 | # define EV_USE_REALTIME 0 |
204 | # define EV_USE_REALTIME 0 |
205 | #endif |
205 | #endif |
206 | |
206 | |
|
|
207 | #if !EV_STAT_ENABLE |
|
|
208 | # undef EV_USE_INOTIFY |
|
|
209 | # define EV_USE_INOTIFY 0 |
|
|
210 | #endif |
|
|
211 | |
|
|
212 | #if EV_USE_INOTIFY |
|
|
213 | # include <sys/inotify.h> |
|
|
214 | #endif |
|
|
215 | |
207 | #if EV_SELECT_IS_WINSOCKET |
216 | #if EV_SELECT_IS_WINSOCKET |
208 | # include <winsock.h> |
217 | # include <winsock.h> |
209 | #endif |
|
|
210 | |
|
|
211 | #if !EV_STAT_ENABLE |
|
|
212 | # define EV_USE_INOTIFY 0 |
|
|
213 | #endif |
|
|
214 | |
|
|
215 | #if EV_USE_INOTIFY |
|
|
216 | # include <sys/inotify.h> |
|
|
217 | #endif |
218 | #endif |
218 | |
219 | |
219 | /**/ |
220 | /**/ |
220 | |
221 | |
221 | /* |
222 | /* |
… | |
… | |
230 | |
231 | |
231 | #define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */ |
232 | #define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */ |
232 | #define MAX_BLOCKTIME 59.743 /* never wait longer than this time (to detect time jumps) */ |
233 | #define MAX_BLOCKTIME 59.743 /* never wait longer than this time (to detect time jumps) */ |
233 | /*#define CLEANUP_INTERVAL (MAX_BLOCKTIME * 5.) /* how often to try to free memory and re-check fds, TODO */ |
234 | /*#define CLEANUP_INTERVAL (MAX_BLOCKTIME * 5.) /* how often to try to free memory and re-check fds, TODO */ |
234 | |
235 | |
235 | #if __GNUC__ >= 3 |
236 | #if __GNUC__ >= 4 |
236 | # define expect(expr,value) __builtin_expect ((expr),(value)) |
237 | # define expect(expr,value) __builtin_expect ((expr),(value)) |
237 | # define noinline __attribute__ ((noinline)) |
238 | # define noinline __attribute__ ((noinline)) |
238 | #else |
239 | #else |
239 | # define expect(expr,value) (expr) |
240 | # define expect(expr,value) (expr) |
240 | # define noinline |
241 | # define noinline |
… | |
… | |
533 | { |
534 | { |
534 | int fd = fdchanges [i]; |
535 | int fd = fdchanges [i]; |
535 | ANFD *anfd = anfds + fd; |
536 | ANFD *anfd = anfds + fd; |
536 | ev_io *w; |
537 | ev_io *w; |
537 | |
538 | |
538 | int events = 0; |
539 | unsigned char events = 0; |
539 | |
540 | |
540 | for (w = (ev_io *)anfd->head; w; w = (ev_io *)((WL)w)->next) |
541 | for (w = (ev_io *)anfd->head; w; w = (ev_io *)((WL)w)->next) |
541 | events |= w->events; |
542 | events |= (unsigned char)w->events; |
542 | |
543 | |
543 | #if EV_SELECT_IS_WINSOCKET |
544 | #if EV_SELECT_IS_WINSOCKET |
544 | if (events) |
545 | if (events) |
545 | { |
546 | { |
546 | unsigned long argp; |
547 | unsigned long argp; |
547 | anfd->handle = _get_osfhandle (fd); |
548 | anfd->handle = _get_osfhandle (fd); |
548 | assert (("libev only supports socket fds in this configuration", ioctlsocket (anfd->handle, FIONREAD, &argp) == 0)); |
549 | assert (("libev only supports socket fds in this configuration", ioctlsocket (anfd->handle, FIONREAD, &argp) == 0)); |
549 | } |
550 | } |
550 | #endif |
551 | #endif |
551 | |
552 | |
|
|
553 | { |
|
|
554 | unsigned char o_events = anfd->events; |
|
|
555 | unsigned char o_reify = anfd->reify; |
|
|
556 | |
552 | anfd->reify = 0; |
557 | anfd->reify = 0; |
553 | |
|
|
554 | backend_modify (EV_A_ fd, anfd->events, events); |
|
|
555 | anfd->events = events; |
558 | anfd->events = events; |
|
|
559 | |
|
|
560 | if (o_events != events || o_reify & EV_IOFDSET) |
|
|
561 | backend_modify (EV_A_ fd, o_events, events); |
|
|
562 | } |
556 | } |
563 | } |
557 | |
564 | |
558 | fdchangecnt = 0; |
565 | fdchangecnt = 0; |
559 | } |
566 | } |
560 | |
567 | |
561 | void inline_size |
568 | void inline_size |
562 | fd_change (EV_P_ int fd, int flags) |
569 | fd_change (EV_P_ int fd, int flags) |
563 | { |
570 | { |
564 | unsigned char reify = anfds [fd].reify; |
571 | unsigned char reify = anfds [fd].reify; |
565 | anfds [fd].reify |= flags | 1; |
572 | anfds [fd].reify |= flags; |
566 | |
573 | |
567 | if (expect_true (!reify)) |
574 | if (expect_true (!reify)) |
568 | { |
575 | { |
569 | ++fdchangecnt; |
576 | ++fdchangecnt; |
570 | array_needsize (int, fdchanges, fdchangemax, fdchangecnt, EMPTY2); |
577 | array_needsize (int, fdchanges, fdchangemax, fdchangecnt, EMPTY2); |
… | |
… | |
628 | |
635 | |
629 | for (fd = 0; fd < anfdmax; ++fd) |
636 | for (fd = 0; fd < anfdmax; ++fd) |
630 | if (anfds [fd].events) |
637 | if (anfds [fd].events) |
631 | { |
638 | { |
632 | anfds [fd].events = 0; |
639 | anfds [fd].events = 0; |
633 | fd_change (EV_A_ fd, EV_IOFDSET); |
640 | fd_change (EV_A_ fd, EV_IOFDSET | 1); |
634 | } |
641 | } |
635 | } |
642 | } |
636 | |
643 | |
637 | /*****************************************************************************/ |
644 | /*****************************************************************************/ |
638 | |
645 | |
… | |
… | |
1031 | #if EV_IDLE_ENABLE |
1038 | #if EV_IDLE_ENABLE |
1032 | array_free (idle, [i]); |
1039 | array_free (idle, [i]); |
1033 | #endif |
1040 | #endif |
1034 | } |
1041 | } |
1035 | |
1042 | |
|
|
1043 | ev_free (anfds); anfdmax = 0; |
|
|
1044 | |
1036 | /* have to use the microsoft-never-gets-it-right macro */ |
1045 | /* have to use the microsoft-never-gets-it-right macro */ |
1037 | array_free (fdchange, EMPTY); |
1046 | array_free (fdchange, EMPTY); |
1038 | array_free (timer, EMPTY); |
1047 | array_free (timer, EMPTY); |
1039 | #if EV_PERIODIC_ENABLE |
1048 | #if EV_PERIODIC_ENABLE |
1040 | array_free (periodic, EMPTY); |
1049 | array_free (periodic, EMPTY); |
|
|
1050 | #endif |
|
|
1051 | #if EV_FORK_ENABLE |
|
|
1052 | array_free (fork, EMPTY); |
1041 | #endif |
1053 | #endif |
1042 | array_free (prepare, EMPTY); |
1054 | array_free (prepare, EMPTY); |
1043 | array_free (check, EMPTY); |
1055 | array_free (check, EMPTY); |
1044 | |
1056 | |
1045 | backend = 0; |
1057 | backend = 0; |
… | |
… | |
1600 | |
1612 | |
1601 | ev_start (EV_A_ (W)w, 1); |
1613 | ev_start (EV_A_ (W)w, 1); |
1602 | array_needsize (ANFD, anfds, anfdmax, fd + 1, anfds_init); |
1614 | array_needsize (ANFD, anfds, anfdmax, fd + 1, anfds_init); |
1603 | wlist_add (&anfds[fd].head, (WL)w); |
1615 | wlist_add (&anfds[fd].head, (WL)w); |
1604 | |
1616 | |
1605 | fd_change (EV_A_ fd, w->events & EV_IOFDSET); |
1617 | fd_change (EV_A_ fd, w->events & EV_IOFDSET | 1); |
1606 | w->events &= ~ EV_IOFDSET; |
1618 | w->events &= ~EV_IOFDSET; |
1607 | } |
1619 | } |
1608 | |
1620 | |
1609 | void noinline |
1621 | void noinline |
1610 | ev_io_stop (EV_P_ ev_io *w) |
1622 | ev_io_stop (EV_P_ ev_io *w) |
1611 | { |
1623 | { |
… | |
… | |
1616 | assert (("ev_io_start called with illegal fd (must stay constant after start!)", w->fd >= 0 && w->fd < anfdmax)); |
1628 | assert (("ev_io_start called with illegal fd (must stay constant after start!)", w->fd >= 0 && w->fd < anfdmax)); |
1617 | |
1629 | |
1618 | wlist_del (&anfds[w->fd].head, (WL)w); |
1630 | wlist_del (&anfds[w->fd].head, (WL)w); |
1619 | ev_stop (EV_A_ (W)w); |
1631 | ev_stop (EV_A_ (W)w); |
1620 | |
1632 | |
1621 | fd_change (EV_A_ w->fd, 0); |
1633 | fd_change (EV_A_ w->fd, 1); |
1622 | } |
1634 | } |
1623 | |
1635 | |
1624 | void noinline |
1636 | void noinline |
1625 | ev_timer_start (EV_P_ ev_timer *w) |
1637 | ev_timer_start (EV_P_ ev_timer *w) |
1626 | { |
1638 | { |
… | |
… | |
2170 | |
2182 | |
2171 | #if EV_EMBED_ENABLE |
2183 | #if EV_EMBED_ENABLE |
2172 | void noinline |
2184 | void noinline |
2173 | ev_embed_sweep (EV_P_ ev_embed *w) |
2185 | ev_embed_sweep (EV_P_ ev_embed *w) |
2174 | { |
2186 | { |
2175 | ev_loop (w->loop, EVLOOP_NONBLOCK); |
2187 | ev_loop (w->other, EVLOOP_NONBLOCK); |
2176 | } |
2188 | } |
2177 | |
2189 | |
2178 | static void |
2190 | static void |
2179 | embed_cb (EV_P_ ev_io *io, int revents) |
2191 | embed_io_cb (EV_P_ ev_io *io, int revents) |
2180 | { |
2192 | { |
2181 | ev_embed *w = (ev_embed *)(((char *)io) - offsetof (ev_embed, io)); |
2193 | ev_embed *w = (ev_embed *)(((char *)io) - offsetof (ev_embed, io)); |
2182 | |
2194 | |
2183 | if (ev_cb (w)) |
2195 | if (ev_cb (w)) |
2184 | ev_feed_event (EV_A_ (W)w, EV_EMBED); |
2196 | ev_feed_event (EV_A_ (W)w, EV_EMBED); |
2185 | else |
2197 | else |
2186 | ev_embed_sweep (loop, w); |
2198 | ev_embed_sweep (loop, w); |
2187 | } |
2199 | } |
2188 | |
2200 | |
|
|
2201 | static void |
|
|
2202 | embed_prepare_cb (EV_P_ ev_prepare *prepare, int revents) |
|
|
2203 | { |
|
|
2204 | ev_embed *w = (ev_embed *)(((char *)prepare) - offsetof (ev_embed, prepare)); |
|
|
2205 | |
|
|
2206 | fd_reify (w->other); |
|
|
2207 | } |
|
|
2208 | |
2189 | void |
2209 | void |
2190 | ev_embed_start (EV_P_ ev_embed *w) |
2210 | ev_embed_start (EV_P_ ev_embed *w) |
2191 | { |
2211 | { |
2192 | if (expect_false (ev_is_active (w))) |
2212 | if (expect_false (ev_is_active (w))) |
2193 | return; |
2213 | return; |
2194 | |
2214 | |
2195 | { |
2215 | { |
2196 | struct ev_loop *loop = w->loop; |
2216 | struct ev_loop *loop = w->other; |
2197 | assert (("loop to be embedded is not embeddable", backend & ev_embeddable_backends ())); |
2217 | assert (("loop to be embedded is not embeddable", backend & ev_embeddable_backends ())); |
2198 | ev_io_init (&w->io, embed_cb, backend_fd, EV_READ); |
2218 | ev_io_init (&w->io, embed_io_cb, backend_fd, EV_WRITE); |
2199 | } |
2219 | } |
2200 | |
2220 | |
2201 | ev_set_priority (&w->io, ev_priority (w)); |
2221 | ev_set_priority (&w->io, ev_priority (w)); |
2202 | ev_io_start (EV_A_ &w->io); |
2222 | ev_io_start (EV_A_ &w->io); |
2203 | |
2223 | |
|
|
2224 | ev_prepare_init (&w->prepare, embed_prepare_cb); |
|
|
2225 | ev_set_priority (&w->prepare, EV_MINPRI); |
|
|
2226 | ev_prepare_start (EV_A_ &w->prepare); |
|
|
2227 | |
2204 | ev_start (EV_A_ (W)w, 1); |
2228 | ev_start (EV_A_ (W)w, 1); |
2205 | } |
2229 | } |
2206 | |
2230 | |
2207 | void |
2231 | void |
2208 | ev_embed_stop (EV_P_ ev_embed *w) |
2232 | ev_embed_stop (EV_P_ ev_embed *w) |
… | |
… | |
2210 | clear_pending (EV_A_ (W)w); |
2234 | clear_pending (EV_A_ (W)w); |
2211 | if (expect_false (!ev_is_active (w))) |
2235 | if (expect_false (!ev_is_active (w))) |
2212 | return; |
2236 | return; |
2213 | |
2237 | |
2214 | ev_io_stop (EV_A_ &w->io); |
2238 | ev_io_stop (EV_A_ &w->io); |
|
|
2239 | ev_prepare_stop (EV_A_ &w->prepare); |
2215 | |
2240 | |
2216 | ev_stop (EV_A_ (W)w); |
2241 | ev_stop (EV_A_ (W)w); |
2217 | } |
2242 | } |
2218 | #endif |
2243 | #endif |
2219 | |
2244 | |
… | |
… | |
2308 | ev_timer_set (&once->to, timeout, 0.); |
2333 | ev_timer_set (&once->to, timeout, 0.); |
2309 | ev_timer_start (EV_A_ &once->to); |
2334 | ev_timer_start (EV_A_ &once->to); |
2310 | } |
2335 | } |
2311 | } |
2336 | } |
2312 | |
2337 | |
|
|
2338 | #if EV_MULTIPLICITY |
|
|
2339 | #include "ev_wrap.h" |
|
|
2340 | #endif |
|
|
2341 | |
2313 | #ifdef __cplusplus |
2342 | #ifdef __cplusplus |
2314 | } |
2343 | } |
2315 | #endif |
2344 | #endif |
2316 | |
2345 | |