--- libev/ev.c 2008/02/01 13:22:48 1.208 +++ libev/ev.c 2008/02/21 10:34:15 1.215 @@ -812,21 +812,20 @@ ev_io_set (&pipeev, evpipe [0], EV_READ); ev_io_start (EV_A_ &pipeev); - ev_unref (EV_A); /* child watcher should not keep loop alive */ + ev_unref (EV_A); /* watcher should not keep loop alive */ } } void inline_size -evpipe_write (EV_P_ int sig, int async) +evpipe_write (EV_P_ EV_ATOMIC_T *flag) { - if (!(gotasync || gotsig)) + if (!*flag) { - int old_errno = errno; - - if (sig) gotsig = 1; - if (async) gotasync = 1; + int old_errno = errno; /* save errno because write might clobber it */ + *flag = 1; write (evpipe [1], &old_errno, 1); + errno = old_errno; } } @@ -839,7 +838,7 @@ read (evpipe [0], &dummy, 1); } - if (gotsig) + if (gotsig && ev_is_default_loop (EV_A)) { int signum; gotsig = 0; @@ -849,6 +848,7 @@ ev_feed_signal_event (EV_A_ signum + 1); } +#if EV_ASYNC_ENABLE if (gotasync) { int i; @@ -861,6 +861,7 @@ ev_feed_event (EV_A_ asyncs [i], EV_ASYNC); } } +#endif } /*****************************************************************************/ @@ -877,7 +878,7 @@ #endif signals [signum - 1].gotsig = 1; - evpipe_write (EV_A_ 1, 0); + evpipe_write (EV_A_ &gotsig); } void noinline @@ -1081,13 +1082,19 @@ } #endif - ev_rt_now = ev_time (); - mn_now = get_clock (); - now_floor = mn_now; - rtmn_diff = ev_rt_now - mn_now; + ev_rt_now = ev_time (); + mn_now = get_clock (); + now_floor = mn_now; + rtmn_diff = ev_rt_now - mn_now; io_blocktime = 0.; timeout_blocktime = 0.; + backend = 0; + backend_fd = -1; + gotasync = 0; +#if EV_USE_INOTIFY + fs_fd = -2; +#endif /* pid check not overridable via env */ #ifndef _WIN32 @@ -1103,12 +1110,6 @@ if (!(flags & 0x0000ffffUL)) flags |= ev_recommended_backends (); - backend = 0; - backend_fd = -1; -#if EV_USE_INOTIFY - fs_fd = -2; -#endif - #if EV_USE_PORT if (!backend && (flags & EVBACKEND_PORT )) backend = port_init (EV_A_ flags); #endif @@ -1189,6 +1190,9 @@ #endif array_free (prepare, EMPTY); array_free (check, EMPTY); +#if EV_ASYNC_ENABLE + array_free (async, EMPTY); +#endif backend = 0; } @@ -1214,7 +1218,11 @@ if (ev_is_active (&pipeev)) { /* this "locks" the handlers against writing to the pipe */ - gotsig = gotasync = 1; + /* while we modify the fd vars */ + gotsig = 1; +#if EV_ASYNC_ENABLE + gotasync = 1; +#endif ev_ref (EV_A); ev_io_stop (EV_A_ &pipeev); @@ -2460,7 +2468,7 @@ ev_async_send (EV_P_ ev_async *w) { w->sent = 1; - evpipe_write (EV_A_ 0, 1); + evpipe_write (EV_A_ &gotasync); } #endif