X-Git-Url: https://git.llucax.com/software/libev.git/blobdiff_plain/9c468d0cd3a409a8c4b1b37d6e161404350d67cb..ba71cf07f3506b8e303130e981d3b5b3e9ea5dc8:/ev.c?ds=sidebyside diff --git a/ev.c b/ev.c index 255a9cd..40e2292 100644 --- a/ev.c +++ b/ev.c @@ -200,7 +200,7 @@ extern "C" { #else # define expect(expr,value) (expr) # define inline_speed static -# define inline_minimal static +# define inline_size static # define noinline #endif @@ -1560,87 +1560,6 @@ ev_periodic_again (EV_P_ ev_periodic *w) } #endif -void -ev_idle_start (EV_P_ ev_idle *w) -{ - if (expect_false (ev_is_active (w))) - return; - - ev_start (EV_A_ (W)w, ++idlecnt); - array_needsize (ev_idle *, idles, idlemax, idlecnt, EMPTY2); - idles [idlecnt - 1] = w; -} - -void -ev_idle_stop (EV_P_ ev_idle *w) -{ - ev_clear_pending (EV_A_ (W)w); - if (expect_false (!ev_is_active (w))) - return; - - { - int active = ((W)w)->active; - idles [active - 1] = idles [--idlecnt]; - ((W)idles [active - 1])->active = active; - } - - ev_stop (EV_A_ (W)w); -} - -void -ev_prepare_start (EV_P_ ev_prepare *w) -{ - if (expect_false (ev_is_active (w))) - return; - - ev_start (EV_A_ (W)w, ++preparecnt); - array_needsize (ev_prepare *, prepares, preparemax, preparecnt, EMPTY2); - prepares [preparecnt - 1] = w; -} - -void -ev_prepare_stop (EV_P_ ev_prepare *w) -{ - ev_clear_pending (EV_A_ (W)w); - if (expect_false (!ev_is_active (w))) - return; - - { - int active = ((W)w)->active; - prepares [active - 1] = prepares [--preparecnt]; - ((W)prepares [active - 1])->active = active; - } - - ev_stop (EV_A_ (W)w); -} - -void -ev_check_start (EV_P_ ev_check *w) -{ - if (expect_false (ev_is_active (w))) - return; - - ev_start (EV_A_ (W)w, ++checkcnt); - array_needsize (ev_check *, checks, checkmax, checkcnt, EMPTY2); - checks [checkcnt - 1] = w; -} - -void -ev_check_stop (EV_P_ ev_check *w) -{ - ev_clear_pending (EV_A_ (W)w); - if (expect_false (!ev_is_active (w))) - return; - - { - int active = ((W)w)->active; - checks [active - 1] = checks [--checkcnt]; - ((W)checks [active - 1])->active = active; - } - - ev_stop (EV_A_ (W)w); -} - #ifndef SA_RESTART # define SA_RESTART 0 #endif @@ -1712,59 +1631,11 @@ ev_child_stop (EV_P_ ev_child *w) ev_stop (EV_A_ (W)w); } -#if EV_EMBED_ENABLE -void noinline -ev_embed_sweep (EV_P_ ev_embed *w) -{ - ev_loop (w->loop, EVLOOP_NONBLOCK); -} - -static void -embed_cb (EV_P_ ev_io *io, int revents) -{ - ev_embed *w = (ev_embed *)(((char *)io) - offsetof (ev_embed, io)); - - if (ev_cb (w)) - ev_feed_event (EV_A_ (W)w, EV_EMBED); - else - ev_embed_sweep (loop, w); -} - -void -ev_embed_start (EV_P_ ev_embed *w) -{ - if (expect_false (ev_is_active (w))) - return; - - { - struct ev_loop *loop = w->loop; - assert (("loop to be embedded is not embeddable", backend & ev_embeddable_backends ())); - ev_io_init (&w->io, embed_cb, backend_fd, EV_READ); - } - - ev_set_priority (&w->io, ev_priority (w)); - ev_io_start (EV_A_ &w->io); - - ev_start (EV_A_ (W)w, 1); -} - -void -ev_embed_stop (EV_P_ ev_embed *w) -{ - ev_clear_pending (EV_A_ (W)w); - if (expect_false (!ev_is_active (w))) - return; - - ev_io_stop (EV_A_ &w->io); - - ev_stop (EV_A_ (W)w); -} -#endif - #if EV_STAT_ENABLE # ifdef _WIN32 -# define lstat(a,b) stat(a,b) +# undef lstat +# define lstat(a,b) _stati64 (a,b) # endif #define DEF_STAT_INTERVAL 5.0074891 @@ -1828,6 +1699,136 @@ ev_stat_stop (EV_P_ ev_stat *w) } #endif +void +ev_idle_start (EV_P_ ev_idle *w) +{ + if (expect_false (ev_is_active (w))) + return; + + ev_start (EV_A_ (W)w, ++idlecnt); + array_needsize (ev_idle *, idles, idlemax, idlecnt, EMPTY2); + idles [idlecnt - 1] = w; +} + +void +ev_idle_stop (EV_P_ ev_idle *w) +{ + ev_clear_pending (EV_A_ (W)w); + if (expect_false (!ev_is_active (w))) + return; + + { + int active = ((W)w)->active; + idles [active - 1] = idles [--idlecnt]; + ((W)idles [active - 1])->active = active; + } + + ev_stop (EV_A_ (W)w); +} + +void +ev_prepare_start (EV_P_ ev_prepare *w) +{ + if (expect_false (ev_is_active (w))) + return; + + ev_start (EV_A_ (W)w, ++preparecnt); + array_needsize (ev_prepare *, prepares, preparemax, preparecnt, EMPTY2); + prepares [preparecnt - 1] = w; +} + +void +ev_prepare_stop (EV_P_ ev_prepare *w) +{ + ev_clear_pending (EV_A_ (W)w); + if (expect_false (!ev_is_active (w))) + return; + + { + int active = ((W)w)->active; + prepares [active - 1] = prepares [--preparecnt]; + ((W)prepares [active - 1])->active = active; + } + + ev_stop (EV_A_ (W)w); +} + +void +ev_check_start (EV_P_ ev_check *w) +{ + if (expect_false (ev_is_active (w))) + return; + + ev_start (EV_A_ (W)w, ++checkcnt); + array_needsize (ev_check *, checks, checkmax, checkcnt, EMPTY2); + checks [checkcnt - 1] = w; +} + +void +ev_check_stop (EV_P_ ev_check *w) +{ + ev_clear_pending (EV_A_ (W)w); + if (expect_false (!ev_is_active (w))) + return; + + { + int active = ((W)w)->active; + checks [active - 1] = checks [--checkcnt]; + ((W)checks [active - 1])->active = active; + } + + ev_stop (EV_A_ (W)w); +} + +#if EV_EMBED_ENABLE +void noinline +ev_embed_sweep (EV_P_ ev_embed *w) +{ + ev_loop (w->loop, EVLOOP_NONBLOCK); +} + +static void +embed_cb (EV_P_ ev_io *io, int revents) +{ + ev_embed *w = (ev_embed *)(((char *)io) - offsetof (ev_embed, io)); + + if (ev_cb (w)) + ev_feed_event (EV_A_ (W)w, EV_EMBED); + else + ev_embed_sweep (loop, w); +} + +void +ev_embed_start (EV_P_ ev_embed *w) +{ + if (expect_false (ev_is_active (w))) + return; + + { + struct ev_loop *loop = w->loop; + assert (("loop to be embedded is not embeddable", backend & ev_embeddable_backends ())); + ev_io_init (&w->io, embed_cb, backend_fd, EV_READ); + } + + ev_set_priority (&w->io, ev_priority (w)); + ev_io_start (EV_A_ &w->io); + + ev_start (EV_A_ (W)w, 1); +} + +void +ev_embed_stop (EV_P_ ev_embed *w) +{ + ev_clear_pending (EV_A_ (W)w); + if (expect_false (!ev_is_active (w))) + return; + + ev_io_stop (EV_A_ &w->io); + + ev_stop (EV_A_ (W)w); +} +#endif + /*****************************************************************************/ struct ev_once