… | |
… | |
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; |
… | |
… | |
1978 | { |
1997 | { |
1979 | queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); |
1998 | queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); |
1980 | call_pending (EV_A); |
1999 | call_pending (EV_A); |
1981 | } |
2000 | } |
1982 | |
2001 | |
1983 | if (expect_false (!activecnt)) |
|
|
1984 | break; |
|
|
1985 | |
|
|
1986 | /* we might have forked, so reify kernel state if necessary */ |
2002 | /* we might have forked, so reify kernel state if necessary */ |
1987 | if (expect_false (postfork)) |
2003 | if (expect_false (postfork)) |
1988 | loop_fork (EV_A); |
2004 | loop_fork (EV_A); |
1989 | |
2005 | |
1990 | /* update fd-related kernel structures */ |
2006 | /* update fd-related kernel structures */ |
… | |
… | |
2155 | |
2171 | |
2156 | if (expect_false (ev_is_active (w))) |
2172 | if (expect_false (ev_is_active (w))) |
2157 | return; |
2173 | return; |
2158 | |
2174 | |
2159 | assert (("libev: ev_io_start called with negative fd", fd >= 0)); |
2175 | 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)))); |
2176 | assert (("libev: ev_io start called with illegal event mask", !(w->events & ~(EV__IOFDSET | EV_READ | EV_WRITE)))); |
2161 | |
2177 | |
2162 | EV_FREQUENT_CHECK; |
2178 | EV_FREQUENT_CHECK; |
2163 | |
2179 | |
2164 | ev_start (EV_A_ (W)w, 1); |
2180 | ev_start (EV_A_ (W)w, 1); |
2165 | array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero); |
2181 | array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero); |
2166 | wlist_add (&anfds[fd].head, (WL)w); |
2182 | wlist_add (&anfds[fd].head, (WL)w); |
2167 | |
2183 | |
2168 | fd_change (EV_A_ fd, w->events & EV_IOFDSET | 1); |
2184 | fd_change (EV_A_ fd, w->events & EV__IOFDSET | 1); |
2169 | w->events &= ~EV_IOFDSET; |
2185 | w->events &= ~EV__IOFDSET; |
2170 | |
2186 | |
2171 | EV_FREQUENT_CHECK; |
2187 | EV_FREQUENT_CHECK; |
2172 | } |
2188 | } |
2173 | |
2189 | |
2174 | void noinline |
2190 | void noinline |
… | |
… | |
3127 | ev_timer_set (&once->to, timeout, 0.); |
3143 | ev_timer_set (&once->to, timeout, 0.); |
3128 | ev_timer_start (EV_A_ &once->to); |
3144 | ev_timer_start (EV_A_ &once->to); |
3129 | } |
3145 | } |
3130 | } |
3146 | } |
3131 | |
3147 | |
|
|
3148 | /*****************************************************************************/ |
|
|
3149 | |
|
|
3150 | #if 0 |
|
|
3151 | void |
|
|
3152 | ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) |
|
|
3153 | { |
|
|
3154 | int i, j; |
|
|
3155 | ev_watcher_list *wl, *wn; |
|
|
3156 | |
|
|
3157 | if (types & (EV_IO | EV_EMBED)) |
|
|
3158 | for (i = 0; i < anfdmax; ++i) |
|
|
3159 | for (wl = anfds [i].head; wl; ) |
|
|
3160 | { |
|
|
3161 | wn = wl->next; |
|
|
3162 | |
|
|
3163 | #if EV_EMBED_ENABLE |
|
|
3164 | if (ev_cb ((ev_io *)wl) == embed_io_cb) |
|
|
3165 | { |
|
|
3166 | if (types & EV_EMBED) |
|
|
3167 | cb (EV_A_ EV_EMBED, ((char *)wl) - offsetof (struct ev_embed, io)); |
|
|
3168 | } |
|
|
3169 | else |
|
|
3170 | #endif |
|
|
3171 | #if EV_USE_INOTIFY |
|
|
3172 | if (ev_cb ((ev_io *)wl) == infy_cb) |
|
|
3173 | ; |
|
|
3174 | else |
|
|
3175 | #endif |
|
|
3176 | if ((ev_io *)wl != &pipeev) |
|
|
3177 | if (types & EV_IO) |
|
|
3178 | cb (EV_A_ EV_IO, wl); |
|
|
3179 | |
|
|
3180 | wl = wn; |
|
|
3181 | } |
|
|
3182 | |
|
|
3183 | if (types & (EV_TIMER | EV_STAT)) |
|
|
3184 | for (i = timercnt + HEAP0; i-- > HEAP0; ) |
|
|
3185 | #if EV_STAT_ENABLE |
|
|
3186 | /*TODO: timer is not always active*/ |
|
|
3187 | if (ev_cb ((ev_timer *)ANHE_w (timers [i])) == stat_timer_cb) |
|
|
3188 | { |
|
|
3189 | if (types & EV_STAT) |
|
|
3190 | cb (EV_A_ EV_STAT, ((char *)ANHE_w (timers [i])) - offsetof (struct ev_stat, timer)); |
|
|
3191 | } |
|
|
3192 | else |
|
|
3193 | #endif |
|
|
3194 | if (types & EV_TIMER) |
|
|
3195 | cb (EV_A_ EV_TIMER, ANHE_w (timers [i])); |
|
|
3196 | |
|
|
3197 | #if EV_PERIODIC_ENABLE |
|
|
3198 | if (types & EV_PERIODIC) |
|
|
3199 | for (i = periodiccnt + HEAP0; i-- > HEAP0; ) |
|
|
3200 | cb (EV_A_ EV_PERIODIC, ANHE_w (periodics [i])); |
|
|
3201 | #endif |
|
|
3202 | |
|
|
3203 | #if EV_IDLE_ENABLE |
|
|
3204 | if (types & EV_IDLE) |
|
|
3205 | for (j = NUMPRI; i--; ) |
|
|
3206 | for (i = idlecnt [j]; i--; ) |
|
|
3207 | cb (EV_A_ EV_IDLE, idles [j][i]); |
|
|
3208 | #endif |
|
|
3209 | |
|
|
3210 | #if EV_FORK_ENABLE |
|
|
3211 | if (types & EV_FORK) |
|
|
3212 | for (i = forkcnt; i--; ) |
|
|
3213 | if (ev_cb (forks [i]) != embed_fork_cb) |
|
|
3214 | cb (EV_A_ EV_FORK, forks [i]); |
|
|
3215 | #endif |
|
|
3216 | |
|
|
3217 | #if EV_ASYNC_ENABLE |
|
|
3218 | if (types & EV_ASYNC) |
|
|
3219 | for (i = asynccnt; i--; ) |
|
|
3220 | cb (EV_A_ EV_ASYNC, asyncs [i]); |
|
|
3221 | #endif |
|
|
3222 | |
|
|
3223 | if (types & EV_PREPARE) |
|
|
3224 | for (i = preparecnt; i--; ) |
|
|
3225 | #if EV_EMBED_ENABLE |
|
|
3226 | if (ev_cb (prepares [i]) != embed_prepare_cb) |
|
|
3227 | #endif |
|
|
3228 | cb (EV_A_ EV_PREPARE, prepares [i]); |
|
|
3229 | |
|
|
3230 | if (types & EV_CHECK) |
|
|
3231 | for (i = checkcnt; i--; ) |
|
|
3232 | cb (EV_A_ EV_CHECK, checks [i]); |
|
|
3233 | |
|
|
3234 | if (types & EV_SIGNAL) |
|
|
3235 | for (i = 0; i < signalmax; ++i) |
|
|
3236 | for (wl = signals [i].head; wl; ) |
|
|
3237 | { |
|
|
3238 | wn = wl->next; |
|
|
3239 | cb (EV_A_ EV_SIGNAL, wl); |
|
|
3240 | wl = wn; |
|
|
3241 | } |
|
|
3242 | |
|
|
3243 | if (types & EV_CHILD) |
|
|
3244 | for (i = EV_PID_HASHSIZE; i--; ) |
|
|
3245 | for (wl = childs [i]; wl; ) |
|
|
3246 | { |
|
|
3247 | wn = wl->next; |
|
|
3248 | cb (EV_A_ EV_CHILD, wl); |
|
|
3249 | wl = wn; |
|
|
3250 | } |
|
|
3251 | /* EV_STAT 0x00001000 /* stat data changed */ |
|
|
3252 | /* EV_EMBED 0x00010000 /* embedded event loop needs sweep */ |
|
|
3253 | } |
|
|
3254 | #endif |
|
|
3255 | |
3132 | #if EV_MULTIPLICITY |
3256 | #if EV_MULTIPLICITY |
3133 | #include "ev_wrap.h" |
3257 | #include "ev_wrap.h" |
3134 | #endif |
3258 | #endif |
3135 | |
3259 | |
3136 | #ifdef __cplusplus |
3260 | #ifdef __cplusplus |