… | |
… | |
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 | |
… | |
… | |
1600 | |
1607 | |
1601 | ev_start (EV_A_ (W)w, 1); |
1608 | ev_start (EV_A_ (W)w, 1); |
1602 | array_needsize (ANFD, anfds, anfdmax, fd + 1, anfds_init); |
1609 | array_needsize (ANFD, anfds, anfdmax, fd + 1, anfds_init); |
1603 | wlist_add (&anfds[fd].head, (WL)w); |
1610 | wlist_add (&anfds[fd].head, (WL)w); |
1604 | |
1611 | |
1605 | fd_change (EV_A_ fd, w->events & EV_IOFDSET); |
1612 | fd_change (EV_A_ fd, w->events & EV_IOFDSET | 1); |
1606 | w->events &= ~ EV_IOFDSET; |
1613 | w->events &= ~EV_IOFDSET; |
1607 | } |
1614 | } |
1608 | |
1615 | |
1609 | void noinline |
1616 | void noinline |
1610 | ev_io_stop (EV_P_ ev_io *w) |
1617 | ev_io_stop (EV_P_ ev_io *w) |
1611 | { |
1618 | { |
… | |
… | |
1616 | assert (("ev_io_start called with illegal fd (must stay constant after start!)", w->fd >= 0 && w->fd < anfdmax)); |
1623 | assert (("ev_io_start called with illegal fd (must stay constant after start!)", w->fd >= 0 && w->fd < anfdmax)); |
1617 | |
1624 | |
1618 | wlist_del (&anfds[w->fd].head, (WL)w); |
1625 | wlist_del (&anfds[w->fd].head, (WL)w); |
1619 | ev_stop (EV_A_ (W)w); |
1626 | ev_stop (EV_A_ (W)w); |
1620 | |
1627 | |
1621 | fd_change (EV_A_ w->fd, 0); |
1628 | fd_change (EV_A_ w->fd, 1); |
1622 | } |
1629 | } |
1623 | |
1630 | |
1624 | void noinline |
1631 | void noinline |
1625 | ev_timer_start (EV_P_ ev_timer *w) |
1632 | ev_timer_start (EV_P_ ev_timer *w) |
1626 | { |
1633 | { |