… | |
… | |
470 | |
470 | |
471 | #define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */ |
471 | #define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */ |
472 | #define MAX_BLOCKTIME 59.743 /* never wait longer than this time (to detect time jumps) */ |
472 | #define MAX_BLOCKTIME 59.743 /* never wait longer than this time (to detect time jumps) */ |
473 | |
473 | |
474 | #define EV_TV_SET(tv,t) do { tv.tv_sec = (long)t; tv.tv_usec = (long)((t - tv.tv_sec) * 1e6); } while (0) |
474 | #define EV_TV_SET(tv,t) do { tv.tv_sec = (long)t; tv.tv_usec = (long)((t - tv.tv_sec) * 1e6); } while (0) |
475 | #define EV_TS_SET(ts,t) do { ts.tv_sec = (long)t; tv.tv_nsec = (long)((t - tv.tv_sec) * 1e9); } while (0) |
475 | #define EV_TS_SET(ts,t) do { ts.tv_sec = (long)t; ts.tv_nsec = (long)((t - ts.tv_sec) * 1e9); } while (0) |
476 | |
476 | |
477 | #if __GNUC__ >= 4 |
477 | #if __GNUC__ >= 4 |
478 | # define expect(expr,value) __builtin_expect ((expr),(value)) |
478 | # define expect(expr,value) __builtin_expect ((expr),(value)) |
479 | # define noinline __attribute__ ((noinline)) |
479 | # define noinline __attribute__ ((noinline)) |
480 | #else |
480 | #else |
… | |
… | |
771 | if (delay > 0.) |
771 | if (delay > 0.) |
772 | { |
772 | { |
773 | #if EV_USE_NANOSLEEP |
773 | #if EV_USE_NANOSLEEP |
774 | struct timespec ts; |
774 | struct timespec ts; |
775 | |
775 | |
776 | EV_SET_TS (ts, delay); |
776 | EV_TS_SET (ts, delay); |
777 | nanosleep (&ts, 0); |
777 | nanosleep (&ts, 0); |
778 | #elif defined(_WIN32) |
778 | #elif defined(_WIN32) |
779 | Sleep ((unsigned long)(delay * 1e3)); |
779 | Sleep ((unsigned long)(delay * 1e3)); |
780 | #else |
780 | #else |
781 | struct timeval tv; |
781 | struct timeval tv; |
782 | |
782 | |
783 | /* here we rely on sys/time.h + sys/types.h + unistd.h providing select */ |
783 | /* here we rely on sys/time.h + sys/types.h + unistd.h providing select */ |
784 | /* something not guaranteed by newer posix versions, but guaranteed */ |
784 | /* something not guaranteed by newer posix versions, but guaranteed */ |
785 | /* by older ones */ |
785 | /* by older ones */ |
786 | EV_SET_TV (tv, delay); |
786 | EV_TV_SET (tv, delay); |
787 | select (0, 0, 0, 0, &tv); |
787 | select (0, 0, 0, 0, &tv); |
788 | #endif |
788 | #endif |
789 | } |
789 | } |
790 | } |
790 | } |
791 | |
791 | |
… | |
… | |
943 | { |
943 | { |
944 | int fd = fdchanges [i]; |
944 | int fd = fdchanges [i]; |
945 | ANFD *anfd = anfds + fd; |
945 | ANFD *anfd = anfds + fd; |
946 | ev_io *w; |
946 | ev_io *w; |
947 | |
947 | |
948 | unsigned char events = 0; |
948 | unsigned char o_events = anfd->events; |
|
|
949 | unsigned char o_reify = anfd->reify; |
949 | |
950 | |
950 | for (w = (ev_io *)anfd->head; w; w = (ev_io *)((WL)w)->next) |
951 | anfd->reify = 0; |
951 | events |= (unsigned char)w->events; |
|
|
952 | |
952 | |
953 | #if EV_SELECT_IS_WINSOCKET |
953 | #if EV_SELECT_IS_WINSOCKET |
954 | if (events) |
954 | if (o_reify & EV__IOFDSET) |
955 | { |
955 | { |
956 | unsigned long arg; |
956 | unsigned long arg; |
957 | anfd->handle = EV_FD_TO_WIN32_HANDLE (fd); |
957 | anfd->handle = EV_FD_TO_WIN32_HANDLE (fd); |
958 | assert (("libev: only socket fds supported in this configuration", ioctlsocket (anfd->handle, FIONREAD, &arg) == 0)); |
958 | assert (("libev: only socket fds supported in this configuration", ioctlsocket (anfd->handle, FIONREAD, &arg) == 0)); |
959 | } |
959 | } |
960 | #endif |
960 | #endif |
961 | |
961 | |
|
|
962 | /*if (expect_true (o_reify & EV_ANFD_REIFY)) probably a deoptimisation */ |
962 | { |
963 | { |
963 | unsigned char o_events = anfd->events; |
|
|
964 | unsigned char o_reify = anfd->reify; |
|
|
965 | |
|
|
966 | anfd->reify = 0; |
|
|
967 | anfd->events = events; |
964 | anfd->events = 0; |
968 | |
965 | |
969 | if (o_events != events || o_reify & EV__IOFDSET) |
966 | for (w = (ev_io *)anfd->head; w; w = (ev_io *)((WL)w)->next) |
|
|
967 | anfd->events |= (unsigned char)w->events; |
|
|
968 | |
|
|
969 | if (o_events !=anfd-> events) |
|
|
970 | o_reify = EV__IOFDSET; /* actually |= */ |
|
|
971 | } |
|
|
972 | |
|
|
973 | if (o_reify & EV__IOFDSET) |
970 | backend_modify (EV_A_ fd, o_events, events); |
974 | backend_modify (EV_A_ fd, o_events, anfd->events); |
971 | } |
|
|
972 | } |
975 | } |
973 | |
976 | |
974 | fdchangecnt = 0; |
977 | fdchangecnt = 0; |
975 | } |
978 | } |
976 | |
979 | |
… | |
… | |
2597 | EV_FREQUENT_CHECK; |
2600 | EV_FREQUENT_CHECK; |
2598 | |
2601 | |
2599 | wlist_del (&anfds[w->fd].head, (WL)w); |
2602 | wlist_del (&anfds[w->fd].head, (WL)w); |
2600 | ev_stop (EV_A_ (W)w); |
2603 | ev_stop (EV_A_ (W)w); |
2601 | |
2604 | |
2602 | fd_change (EV_A_ w->fd, 1); |
2605 | fd_change (EV_A_ w->fd, EV_ANFD_REIFY); |
2603 | |
2606 | |
2604 | EV_FREQUENT_CHECK; |
2607 | EV_FREQUENT_CHECK; |
2605 | } |
2608 | } |
2606 | |
2609 | |
2607 | void noinline |
2610 | void noinline |