… | |
… | |
64 | # if HAVE_CLOCK_GETTIME |
64 | # if HAVE_CLOCK_GETTIME |
65 | # ifndef EV_USE_MONOTONIC |
65 | # ifndef EV_USE_MONOTONIC |
66 | # define EV_USE_MONOTONIC 1 |
66 | # define EV_USE_MONOTONIC 1 |
67 | # endif |
67 | # endif |
68 | # ifndef EV_USE_REALTIME |
68 | # ifndef EV_USE_REALTIME |
69 | # define EV_USE_REALTIME 1 |
69 | # define EV_USE_REALTIME 0 |
70 | # endif |
70 | # endif |
71 | # else |
71 | # else |
72 | # ifndef EV_USE_MONOTONIC |
72 | # ifndef EV_USE_MONOTONIC |
73 | # define EV_USE_MONOTONIC 0 |
73 | # define EV_USE_MONOTONIC 0 |
74 | # endif |
74 | # endif |
… | |
… | |
193 | # define EV_USE_MONOTONIC 0 |
193 | # define EV_USE_MONOTONIC 0 |
194 | # endif |
194 | # endif |
195 | #endif |
195 | #endif |
196 | |
196 | |
197 | #ifndef EV_USE_REALTIME |
197 | #ifndef EV_USE_REALTIME |
198 | # define EV_USE_REALTIME 0 |
198 | # define EV_USE_REALTIME !EV_USE_CLOCK_SYSCALL |
199 | #endif |
199 | #endif |
200 | |
200 | |
201 | #ifndef EV_USE_NANOSLEEP |
201 | #ifndef EV_USE_NANOSLEEP |
202 | # if _POSIX_C_SOURCE >= 199309L |
202 | # if _POSIX_C_SOURCE >= 199309L |
203 | # define EV_USE_NANOSLEEP 1 |
203 | # define EV_USE_NANOSLEEP 1 |
… | |
… | |
397 | typedef ev_watcher_time *WT; |
397 | typedef ev_watcher_time *WT; |
398 | |
398 | |
399 | #define ev_active(w) ((W)(w))->active |
399 | #define ev_active(w) ((W)(w))->active |
400 | #define ev_at(w) ((WT)(w))->at |
400 | #define ev_at(w) ((WT)(w))->at |
401 | |
401 | |
402 | #if EV_USE_MONOTONIC |
402 | #if EV_USE_REALTIME |
403 | /* sig_atomic_t is used to avoid per-thread variables or locking but still */ |
403 | /* sig_atomic_t is used to avoid per-thread variables or locking but still */ |
404 | /* giving it a reasonably high chance of working on typical architetcures */ |
404 | /* giving it a reasonably high chance of working on typical architetcures */ |
|
|
405 | static EV_ATOMIC_T have_realtime; /* did clock_gettime (CLOCK_REALTIME) work? */ |
|
|
406 | #endif |
|
|
407 | |
|
|
408 | #if EV_USE_MONOTONIC |
405 | static EV_ATOMIC_T have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */ |
409 | static EV_ATOMIC_T have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */ |
406 | #endif |
410 | #endif |
407 | |
411 | |
408 | #ifdef _WIN32 |
412 | #ifdef _WIN32 |
409 | # include "ev_win32.c" |
413 | # include "ev_win32.c" |
… | |
… | |
553 | |
557 | |
554 | ev_tstamp |
558 | ev_tstamp |
555 | ev_time (void) |
559 | ev_time (void) |
556 | { |
560 | { |
557 | #if EV_USE_REALTIME |
561 | #if EV_USE_REALTIME |
|
|
562 | if (expect_true (have_realtime)) |
|
|
563 | { |
558 | struct timespec ts; |
564 | struct timespec ts; |
559 | clock_gettime (CLOCK_REALTIME, &ts); |
565 | clock_gettime (CLOCK_REALTIME, &ts); |
560 | return ts.tv_sec + ts.tv_nsec * 1e-9; |
566 | return ts.tv_sec + ts.tv_nsec * 1e-9; |
561 | #else |
567 | } |
|
|
568 | #endif |
|
|
569 | |
562 | struct timeval tv; |
570 | struct timeval tv; |
563 | gettimeofday (&tv, 0); |
571 | gettimeofday (&tv, 0); |
564 | return tv.tv_sec + tv.tv_usec * 1e-6; |
572 | return tv.tv_sec + tv.tv_usec * 1e-6; |
565 | #endif |
|
|
566 | } |
573 | } |
567 | |
574 | |
568 | ev_tstamp inline_size |
575 | ev_tstamp inline_size |
569 | get_clock (void) |
576 | get_clock (void) |
570 | { |
577 | { |
… | |
… | |
669 | fprintf (stderr, "slimmed down " # stem " to %d\n", stem ## max);/*D*/\ |
676 | fprintf (stderr, "slimmed down " # stem " to %d\n", stem ## max);/*D*/\ |
670 | } |
677 | } |
671 | #endif |
678 | #endif |
672 | |
679 | |
673 | #define array_free(stem, idx) \ |
680 | #define array_free(stem, idx) \ |
674 | ev_free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0; |
681 | ev_free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0; stem ## s idx = 0 |
675 | |
682 | |
676 | /*****************************************************************************/ |
683 | /*****************************************************************************/ |
677 | |
684 | |
678 | void noinline |
685 | void noinline |
679 | ev_feed_event (EV_P_ void *w, int revents) |
686 | ev_feed_event (EV_P_ void *w, int revents) |
… | |
… | |
759 | unsigned char o_reify = anfd->reify; |
766 | unsigned char o_reify = anfd->reify; |
760 | |
767 | |
761 | anfd->reify = 0; |
768 | anfd->reify = 0; |
762 | anfd->events = events; |
769 | anfd->events = events; |
763 | |
770 | |
764 | if (o_events != events || o_reify & EV_IOFDSET) |
771 | if (o_events != events || o_reify & EV__IOFDSET) |
765 | backend_modify (EV_A_ fd, o_events, events); |
772 | backend_modify (EV_A_ fd, o_events, events); |
766 | } |
773 | } |
767 | } |
774 | } |
768 | |
775 | |
769 | fdchangecnt = 0; |
776 | fdchangecnt = 0; |
… | |
… | |
840 | for (fd = 0; fd < anfdmax; ++fd) |
847 | for (fd = 0; fd < anfdmax; ++fd) |
841 | if (anfds [fd].events) |
848 | if (anfds [fd].events) |
842 | { |
849 | { |
843 | anfds [fd].events = 0; |
850 | anfds [fd].events = 0; |
844 | anfds [fd].emask = 0; |
851 | anfds [fd].emask = 0; |
845 | fd_change (EV_A_ fd, EV_IOFDSET | 1); |
852 | fd_change (EV_A_ fd, EV__IOFDSET | 1); |
846 | } |
853 | } |
847 | } |
854 | } |
848 | |
855 | |
849 | /*****************************************************************************/ |
856 | /*****************************************************************************/ |
850 | |
857 | |
… | |
… | |
1319 | static void noinline |
1326 | static void noinline |
1320 | loop_init (EV_P_ unsigned int flags) |
1327 | loop_init (EV_P_ unsigned int flags) |
1321 | { |
1328 | { |
1322 | if (!backend) |
1329 | if (!backend) |
1323 | { |
1330 | { |
|
|
1331 | #if EV_USE_REALTIME |
|
|
1332 | if (!have_realtime) |
|
|
1333 | { |
|
|
1334 | struct timespec ts; |
|
|
1335 | |
|
|
1336 | if (!clock_gettime (CLOCK_REALTIME, &ts)) |
|
|
1337 | have_realtime = 1; |
|
|
1338 | } |
|
|
1339 | #endif |
|
|
1340 | |
1324 | #if EV_USE_MONOTONIC |
1341 | #if EV_USE_MONOTONIC |
|
|
1342 | if (!have_monotonic) |
1325 | { |
1343 | { |
1326 | struct timespec ts; |
1344 | struct timespec ts; |
|
|
1345 | |
1327 | if (!clock_gettime (CLOCK_MONOTONIC, &ts)) |
1346 | if (!clock_gettime (CLOCK_MONOTONIC, &ts)) |
1328 | have_monotonic = 1; |
1347 | have_monotonic = 1; |
1329 | } |
1348 | } |
1330 | #endif |
1349 | #endif |
1331 | |
1350 | |
1332 | ev_rt_now = ev_time (); |
1351 | ev_rt_now = ev_time (); |
1333 | mn_now = get_clock (); |
1352 | mn_now = get_clock (); |
1334 | now_floor = mn_now; |
1353 | now_floor = mn_now; |
… | |
… | |
2155 | |
2174 | |
2156 | if (expect_false (ev_is_active (w))) |
2175 | if (expect_false (ev_is_active (w))) |
2157 | return; |
2176 | return; |
2158 | |
2177 | |
2159 | assert (("libev: ev_io_start called with negative fd", fd >= 0)); |
2178 | assert (("libev: ev_io_start called with negative fd", fd >= 0)); |
2160 | assert (("libev: ev_io start called with illegal event mask", !(w->events & ~(EV_IOFDSET | EV_READ | EV_WRITE)))); |
2179 | assert (("libev: ev_io start called with illegal event mask", !(w->events & ~(EV__IOFDSET | EV_READ | EV_WRITE)))); |
2161 | |
2180 | |
2162 | EV_FREQUENT_CHECK; |
2181 | EV_FREQUENT_CHECK; |
2163 | |
2182 | |
2164 | ev_start (EV_A_ (W)w, 1); |
2183 | ev_start (EV_A_ (W)w, 1); |
2165 | array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero); |
2184 | array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero); |
2166 | wlist_add (&anfds[fd].head, (WL)w); |
2185 | wlist_add (&anfds[fd].head, (WL)w); |
2167 | |
2186 | |
2168 | fd_change (EV_A_ fd, w->events & EV_IOFDSET | 1); |
2187 | fd_change (EV_A_ fd, w->events & EV__IOFDSET | 1); |
2169 | w->events &= ~EV_IOFDSET; |
2188 | w->events &= ~EV__IOFDSET; |
2170 | |
2189 | |
2171 | EV_FREQUENT_CHECK; |
2190 | EV_FREQUENT_CHECK; |
2172 | } |
2191 | } |
2173 | |
2192 | |
2174 | void noinline |
2193 | void noinline |