X-Git-Url: https://git.llucax.com/software/libev.git/blobdiff_plain/1ae67bd246932c3faa0d45fdfd0469a7a46473bd..6fb30a67f78730c733f64429f327e360ea2acaf3:/ev.c diff --git a/ev.c b/ev.c index bd833e9..a111beb 100644 --- a/ev.c +++ b/ev.c @@ -204,11 +204,8 @@ extern "C" { # define EV_USE_REALTIME 0 #endif -#if EV_SELECT_IS_WINSOCKET -# include -#endif - #if !EV_STAT_ENABLE +# undef EV_USE_INOTIFY # define EV_USE_INOTIFY 0 #endif @@ -216,6 +213,10 @@ extern "C" { # include #endif +#if EV_SELECT_IS_WINSOCKET +# include +#endif + /**/ /* @@ -232,7 +233,7 @@ extern "C" { #define MAX_BLOCKTIME 59.743 /* never wait longer than this time (to detect time jumps) */ /*#define CLEANUP_INTERVAL (MAX_BLOCKTIME * 5.) /* how often to try to free memory and re-check fds, TODO */ -#if __GNUC__ >= 3 +#if __GNUC__ >= 4 # define expect(expr,value) __builtin_expect ((expr),(value)) # define noinline __attribute__ ((noinline)) #else @@ -535,10 +536,10 @@ fd_reify (EV_P) ANFD *anfd = anfds + fd; ev_io *w; - int events = 0; + unsigned char events = 0; for (w = (ev_io *)anfd->head; w; w = (ev_io *)((WL)w)->next) - events |= w->events; + events |= (unsigned char)w->events; #if EV_SELECT_IS_WINSOCKET if (events) @@ -549,10 +550,16 @@ fd_reify (EV_P) } #endif - anfd->reify = 0; + { + unsigned char o_events = anfd->events; + unsigned char o_reify = anfd->reify; + + anfd->reify = 0; + anfd->events = events; - backend_modify (EV_A_ fd, anfd->events, events); - anfd->events = events; + if (o_events != events || o_reify & EV_IOFDSET) + backend_modify (EV_A_ fd, o_events, events); + } } fdchangecnt = 0; @@ -562,7 +569,7 @@ void inline_size fd_change (EV_P_ int fd, int flags) { unsigned char reify = anfds [fd].reify; - anfds [fd].reify |= flags | 1; + anfds [fd].reify |= flags; if (expect_true (!reify)) { @@ -630,7 +637,7 @@ fd_rearm_all (EV_P) if (anfds [fd].events) { anfds [fd].events = 0; - fd_change (EV_A_ fd, EV_IOFDSET); + fd_change (EV_A_ fd, EV_IOFDSET | 1); } } @@ -1033,11 +1040,16 @@ loop_destroy (EV_P) #endif } + ev_free (anfds); anfdmax = 0; + /* have to use the microsoft-never-gets-it-right macro */ array_free (fdchange, EMPTY); array_free (timer, EMPTY); #if EV_PERIODIC_ENABLE array_free (periodic, EMPTY); +#endif +#if EV_FORK_ENABLE + array_free (fork, EMPTY); #endif array_free (prepare, EMPTY); array_free (check, EMPTY); @@ -1602,8 +1614,8 @@ ev_io_start (EV_P_ ev_io *w) array_needsize (ANFD, anfds, anfdmax, fd + 1, anfds_init); wlist_add (&anfds[fd].head, (WL)w); - fd_change (EV_A_ fd, w->events & EV_IOFDSET); - w->events &= ~ EV_IOFDSET; + fd_change (EV_A_ fd, w->events & EV_IOFDSET | 1); + w->events &= ~EV_IOFDSET; } void noinline @@ -1618,7 +1630,7 @@ ev_io_stop (EV_P_ ev_io *w) wlist_del (&anfds[w->fd].head, (WL)w); ev_stop (EV_A_ (W)w); - fd_change (EV_A_ w->fd, 0); + fd_change (EV_A_ w->fd, 1); } void noinline