--- libev/ev.c 2010/10/24 17:58:41 1.359 +++ libev/ev.c 2010/10/24 18:12:41 1.360 @@ -1815,6 +1815,9 @@ #if EV_FORK_ENABLE array_free (fork, EMPTY); #endif +#if EV_CLEANUP_ENABLE + array_free (cleanup, EMPTY); +#endif array_free (prepare, EMPTY); array_free (check, EMPTY); #if EV_ASYNC_ENABLE @@ -1987,6 +1990,11 @@ array_verify (EV_A_ (W *)forks, forkcnt); #endif +#if EV_CLEANUP_ENABLE + assert (cleanupmax >= cleanupcnt); + array_verify (EV_A_ (W *)cleanups, cleanupcnt); +#endif + #if EV_ASYNC_ENABLE assert (asyncmax >= asynccnt); array_verify (EV_A_ (W *)asyncs, asynccnt); @@ -3559,6 +3567,44 @@ } ev_stop (EV_A_ (W)w); + + EV_FREQUENT_CHECK; +} +#endif + +#if EV_CLEANUP_ENABLE +void +ev_cleanup_start (EV_P_ ev_cleanup *w) +{ + if (expect_false (ev_is_active (w))) + return; + + EV_FREQUENT_CHECK; + + ev_start (EV_A_ (W)w, ++cleanupcnt); + array_needsize (ev_cleanup *, cleanups, cleanupmax, cleanupcnt, EMPTY2); + cleanups [cleanupcnt - 1] = w; + + EV_FREQUENT_CHECK; +} + +void +ev_cleanup_stop (EV_P_ ev_cleanup *w) +{ + clear_pending (EV_A_ (W)w); + if (expect_false (!ev_is_active (w))) + return; + + EV_FREQUENT_CHECK; + + { + int active = ev_active (w); + + cleanups [active - 1] = cleanups [--cleanupcnt]; + ev_active (cleanups [active - 1]) = active; + } + + ev_stop (EV_A_ (W)w); EV_FREQUENT_CHECK; }