X-Git-Url: https://git.llucax.com/software/libev.git/blobdiff_plain/0af52f411dbf7d205e84883d4557a4af01533ac0..b4ea51ffb8ad1cf82bc52c03035eb335e2b4c88c:/ev.c diff --git a/ev.c b/ev.c index 361d26f..823b68c 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) { @@ -1268,7 +1276,7 @@ periodics_reschedule (EV_P) void inline_size idle_reify (EV_P) { - if (expect_false (!idleall)) + if (expect_false (idleall)) { int pri; @@ -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); @@ -1525,7 +1533,7 @@ wlist_del (WL *head, WL elem) } void inline_speed -ev_clear_pending (EV_P_ W w) +clear_pending (EV_P_ W w) { if (w->pending) { @@ -1534,6 +1542,23 @@ ev_clear_pending (EV_P_ W w) } } +int +ev_clear_pending (EV_P_ void *w) +{ + W w_ = (W)w; + int pending = w_->pending; + + if (expect_true (pending)) + { + ANPENDING *p = pendings [ABSPRI (w_)] + pending - 1; + w_->pending = 0; + p->w = 0; + return p->events; + } + else + return 0; +} + void inline_size pri_adjust (EV_P_ W w) { @@ -1560,7 +1585,7 @@ ev_stop (EV_P_ W w) /*****************************************************************************/ -void +void noinline ev_io_start (EV_P_ ev_io *w) { int fd = w->fd; @@ -1577,10 +1602,10 @@ ev_io_start (EV_P_ ev_io *w) fd_change (EV_A_ fd); } -void +void noinline ev_io_stop (EV_P_ ev_io *w) { - ev_clear_pending (EV_A_ (W)w); + clear_pending (EV_A_ (W)w); if (expect_false (!ev_is_active (w))) return; @@ -1592,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))) @@ -1610,10 +1635,10 @@ 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) { - ev_clear_pending (EV_A_ (W)w); + clear_pending (EV_A_ (W)w); if (expect_false (!ev_is_active (w))) return; @@ -1634,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)) @@ -1655,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))) @@ -1678,10 +1703,10 @@ 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) { - ev_clear_pending (EV_A_ (W)w); + clear_pending (EV_A_ (W)w); if (expect_false (!ev_is_active (w))) return; @@ -1700,7 +1725,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 */ @@ -1713,7 +1738,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 @@ -1742,10 +1767,10 @@ ev_signal_start (EV_P_ ev_signal *w) } } -void +void noinline ev_signal_stop (EV_P_ ev_signal *w) { - ev_clear_pending (EV_A_ (W)w); + clear_pending (EV_A_ (W)w); if (expect_false (!ev_is_active (w))) return; @@ -1772,7 +1797,7 @@ ev_child_start (EV_P_ ev_child *w) void ev_child_stop (EV_P_ ev_child *w) { - ev_clear_pending (EV_A_ (W)w); + clear_pending (EV_A_ (W)w); if (expect_false (!ev_is_active (w))) return; @@ -2018,7 +2043,7 @@ ev_stat_start (EV_P_ ev_stat *w) void ev_stat_stop (EV_P_ ev_stat *w) { - ev_clear_pending (EV_A_ (W)w); + clear_pending (EV_A_ (W)w); if (expect_false (!ev_is_active (w))) return; @@ -2054,7 +2079,7 @@ ev_idle_start (EV_P_ ev_idle *w) void ev_idle_stop (EV_P_ ev_idle *w) { - ev_clear_pending (EV_A_ (W)w); + clear_pending (EV_A_ (W)w); if (expect_false (!ev_is_active (w))) return; @@ -2084,7 +2109,7 @@ ev_prepare_start (EV_P_ ev_prepare *w) void ev_prepare_stop (EV_P_ ev_prepare *w) { - ev_clear_pending (EV_A_ (W)w); + clear_pending (EV_A_ (W)w); if (expect_false (!ev_is_active (w))) return; @@ -2111,7 +2136,7 @@ ev_check_start (EV_P_ ev_check *w) void ev_check_stop (EV_P_ ev_check *w) { - ev_clear_pending (EV_A_ (W)w); + clear_pending (EV_A_ (W)w); if (expect_false (!ev_is_active (w))) return; @@ -2163,7 +2188,7 @@ ev_embed_start (EV_P_ ev_embed *w) void ev_embed_stop (EV_P_ ev_embed *w) { - ev_clear_pending (EV_A_ (W)w); + clear_pending (EV_A_ (W)w); if (expect_false (!ev_is_active (w))) return; @@ -2188,7 +2213,7 @@ ev_fork_start (EV_P_ ev_fork *w) void ev_fork_stop (EV_P_ ev_fork *w) { - ev_clear_pending (EV_A_ (W)w); + clear_pending (EV_A_ (W)w); if (expect_false (!ev_is_active (w))) return;