X-Git-Url: https://git.llucax.com/software/libev.git/blobdiff_plain/74ab025f4b269ca1365059e6e07834e452adfabc..7c3494003f656e9809ed0729b2d408f68b4b610d:/ev.c diff --git a/ev.c b/ev.c index 260787d..3fc528a 100644 --- a/ev.c +++ b/ev.c @@ -224,23 +224,24 @@ extern "C" { #if __GNUC__ >= 3 # define expect(expr,value) __builtin_expect ((expr),(value)) -# define inline_size static inline /* inline for codesize */ -# if EV_MINIMAL -# define noinline __attribute__ ((noinline)) -# define inline_speed static noinline -# else -# define noinline -# define inline_speed static inline -# endif +# define noinline __attribute__ ((noinline)) #else # define expect(expr,value) (expr) -# define inline_speed static -# define inline_size static # define noinline +# if __STDC_VERSION__ < 199901L +# define inline +# endif #endif #define expect_false(expr) expect ((expr) != 0, 0) #define expect_true(expr) expect ((expr) != 0, 1) +#define inline_size static inline + +#if EV_MINIMAL +# define inline_speed static noinline +#else +# define inline_speed static inline +#endif #define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) #define ABSPRI(w) (((W)w)->priority - EV_MINPRI) @@ -419,7 +420,7 @@ array_nextsize (int elem, int cur, int cnt) return ncur; } -inline_speed void * +static noinline void * array_realloc (int elem, void *base, int *cur, int cnt) { *cur = array_nextsize (elem, *cur, cnt); @@ -454,17 +455,17 @@ void noinline ev_feed_event (EV_P_ void *w, int revents) { W w_ = (W)w; + int pri = ABSPRI (w_); if (expect_false (w_->pending)) + pendings [pri][w_->pending - 1].events |= revents; + else { - pendings [ABSPRI (w_)][w_->pending - 1].events |= revents; - return; + w_->pending = ++pendingcnt [pri]; + array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, EMPTY2); + pendings [pri][w_->pending - 1].w = w_; + pendings [pri][w_->pending - 1].events = revents; } - - w_->pending = ++pendingcnt [ABSPRI (w_)]; - array_needsize (ANPENDING, pendings [ABSPRI (w_)], pendingmax [ABSPRI (w_)], pendingcnt [ABSPRI (w_)], EMPTY2); - pendings [ABSPRI (w_)][w_->pending - 1].w = w_; - pendings [ABSPRI (w_)][w_->pending - 1].events = revents; } void inline_size @@ -509,7 +510,8 @@ fd_event (EV_P_ int fd, int revents) void ev_feed_fd_event (EV_P_ int fd, int revents) { - fd_event (EV_A_ fd, revents); + if (fd >= 0 && fd < anfdmax) + fd_event (EV_A_ fd, revents); } void inline_size @@ -749,7 +751,7 @@ sigcb (EV_P_ ev_io *iow, int revents) ev_feed_signal_event (EV_A_ signum + 1); } -void inline_size +void inline_speed fd_intern (int fd) { #ifdef _WIN32 @@ -1165,6 +1167,12 @@ ev_default_fork (void) /*****************************************************************************/ +void +ev_invoke (EV_P_ void *w, int revents) +{ + EV_CB_INVOKE ((W)w, revents); +} + void inline_speed call_pending (EV_P) { @@ -1231,7 +1239,7 @@ periodics_reify (EV_P) } else if (w->interval) { - ((WT)w)->at += floor ((ev_rt_now - ((WT)w)->at) / w->interval + 1.) * w->interval; + ((WT)w)->at = w->offset + floor ((ev_rt_now - w->offset) / w->interval + 1.) * w->interval; assert (("ev_periodic timeout in the past detected while processing timers, negative interval?", ((WT)w)->at > ev_rt_now)); downheap ((WT *)periodics, periodiccnt, 0); } @@ -1255,7 +1263,7 @@ periodics_reschedule (EV_P) if (w->reschedule_cb) ((WT)w)->at = w->reschedule_cb (w, ev_rt_now); else if (w->interval) - ((WT)w)->at += ceil ((ev_rt_now - ((WT)w)->at) / w->interval) * w->interval; + ((WT)w)->at = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; } /* now rebuild the heap */ @@ -1408,7 +1416,7 @@ ev_loop (EV_P_ int flags) } #endif - /* queue check watchers (and execute them) */ + /* queue prepare watchers (and execute them) */ if (expect_false (preparecnt)) { queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); @@ -1540,14 +1548,15 @@ ev_clear_pending (EV_P_ void *w) W w_ = (W)w; int pending = w_->pending; - if (!pending) + if (expect_true (pending)) + { + ANPENDING *p = pendings [ABSPRI (w_)] + pending - 1; + w_->pending = 0; + p->w = 0; + return p->events; + } + else return 0; - - w_->pending = 0; - ANPENDING *p = pendings [ABSPRI (w_)] + pending - 1; - p->w = 0; - - return p->events; } void inline_size @@ -1576,7 +1585,7 @@ ev_stop (EV_P_ W w) /*****************************************************************************/ -void +void noinline ev_io_start (EV_P_ ev_io *w) { int fd = w->fd; @@ -1593,7 +1602,7 @@ ev_io_start (EV_P_ ev_io *w) fd_change (EV_A_ fd); } -void +void noinline ev_io_stop (EV_P_ ev_io *w) { clear_pending (EV_A_ (W)w); @@ -1608,7 +1617,7 @@ ev_io_stop (EV_P_ ev_io *w) fd_change (EV_A_ w->fd); } -void +void noinline ev_timer_start (EV_P_ ev_timer *w) { if (expect_false (ev_is_active (w))) @@ -1626,7 +1635,7 @@ ev_timer_start (EV_P_ ev_timer *w) /*assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w));*/ } -void +void noinline ev_timer_stop (EV_P_ ev_timer *w) { clear_pending (EV_A_ (W)w); @@ -1650,7 +1659,7 @@ ev_timer_stop (EV_P_ ev_timer *w) ev_stop (EV_A_ (W)w); } -void +void noinline ev_timer_again (EV_P_ ev_timer *w) { if (ev_is_active (w)) @@ -1671,7 +1680,7 @@ ev_timer_again (EV_P_ ev_timer *w) } #if EV_PERIODIC_ENABLE -void +void noinline ev_periodic_start (EV_P_ ev_periodic *w) { if (expect_false (ev_is_active (w))) @@ -1683,8 +1692,10 @@ ev_periodic_start (EV_P_ ev_periodic *w) { assert (("ev_periodic_start called with negative interval value", w->interval >= 0.)); /* this formula differs from the one in periodic_reify because we do not always round up */ - ((WT)w)->at += ceil ((ev_rt_now - ((WT)w)->at) / w->interval) * w->interval; + ((WT)w)->at = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; } + else + ((WT)w)->at = w->offset; ev_start (EV_A_ (W)w, ++periodiccnt); array_needsize (ev_periodic *, periodics, periodicmax, periodiccnt, EMPTY2); @@ -1694,7 +1705,7 @@ ev_periodic_start (EV_P_ ev_periodic *w) /*assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w));*/ } -void +void noinline ev_periodic_stop (EV_P_ ev_periodic *w) { clear_pending (EV_A_ (W)w); @@ -1716,7 +1727,7 @@ ev_periodic_stop (EV_P_ ev_periodic *w) ev_stop (EV_A_ (W)w); } -void +void noinline ev_periodic_again (EV_P_ ev_periodic *w) { /* TODO: use adjustheap and recalculation */ @@ -1729,7 +1740,7 @@ ev_periodic_again (EV_P_ ev_periodic *w) # define SA_RESTART 0 #endif -void +void noinline ev_signal_start (EV_P_ ev_signal *w) { #if EV_MULTIPLICITY @@ -1758,7 +1769,7 @@ ev_signal_start (EV_P_ ev_signal *w) } } -void +void noinline ev_signal_stop (EV_P_ ev_signal *w) { clear_pending (EV_A_ (W)w);