X-Git-Url: https://git.llucax.com/software/libev.git/blobdiff_plain/8eaf72b24298b3c7c6e33812b1410b1ee3bb33c6..4f1dc6c0e6bd6e6e6edab0e55fc6b96824a12f38:/ev.c?ds=sidebyside diff --git a/ev.c b/ev.c index 266cbf8..299ba00 100644 --- a/ev.c +++ b/ev.c @@ -37,23 +37,27 @@ extern "C" { # include "config.h" # if HAVE_CLOCK_GETTIME -# define EV_USE_MONOTONIC 1 -# define EV_USE_REALTIME 1 +# ifndef EV_USE_MONOTONIC +# define EV_USE_MONOTONIC 1 +# endif +# ifndef EV_USE_REALTIME +# define EV_USE_REALTIME 1 +# endif # endif -# if HAVE_SELECT && HAVE_SYS_SELECT_H +# if HAVE_SELECT && HAVE_SYS_SELECT_H && !defined (EV_USE_SELECT) # define EV_USE_SELECT 1 # endif -# if HAVE_POLL && HAVE_POLL_H +# if HAVE_POLL && HAVE_POLL_H && !defined (EV_USE_POLL) # define EV_USE_POLL 1 # endif -# if HAVE_EPOLL && HAVE_EPOLL_CTL && HAVE_SYS_EPOLL_H +# if HAVE_EPOLL && HAVE_EPOLL_CTL && HAVE_SYS_EPOLL_H && !defined (EV_USE_EPOLL) # define EV_USE_EPOLL 1 # endif -# if HAVE_KQUEUE && HAVE_SYS_EVENT_H && HAVE_SYS_QUEUE_H +# if HAVE_KQUEUE && HAVE_SYS_EVENT_H && HAVE_SYS_QUEUE_H && !defined (EV_USE_KQUEUE) # define EV_USE_KQUEUE 1 # endif @@ -159,7 +163,9 @@ typedef struct ev_watcher_time *WT; static int have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */ -#include "ev_win32.c" +#ifdef WIN32 +# include "ev_win32.c" +#endif /*****************************************************************************/ @@ -229,6 +235,7 @@ typedef struct struct ev_loop { ev_tstamp ev_rt_now; + #define ev_rt_now ((loop)->ev_rt_now) #define VAR(name,decl) decl; #include "ev_vars.h" #undef VAR @@ -530,15 +537,10 @@ downheap (WT *heap, int N, int k) } inline void -adjustheap (WT *heap, int N, int k, ev_tstamp at) +adjustheap (WT *heap, int N, int k) { - ev_tstamp old_at = heap [k]->at; - heap [k]->at = at; - - if (old_at < at) - downheap (heap, N, k); - else - upheap (heap, k); + upheap (heap, k); + downheap (heap, N, k); } /*****************************************************************************/ @@ -1348,7 +1350,7 @@ ev_timer_stop (EV_P_ struct ev_timer *w) if (((W)w)->active < timercnt--) { timers [((W)w)->active - 1] = timers [timercnt]; - downheap ((WT *)timers, timercnt, ((W)w)->active - 1); + adjustheap ((WT *)timers, timercnt, ((W)w)->active - 1); } ((WT)w)->at -= mn_now; @@ -1362,7 +1364,10 @@ ev_timer_again (EV_P_ struct ev_timer *w) if (ev_is_active (w)) { if (w->repeat) - adjustheap ((WT *)timers, timercnt, ((W)w)->active - 1, mn_now + w->repeat); + { + ((WT)w)->at = mn_now + w->repeat; + adjustheap ((WT *)timers, timercnt, ((W)w)->active - 1); + } else ev_timer_stop (EV_A_ w); } @@ -1406,7 +1411,7 @@ ev_periodic_stop (EV_P_ struct ev_periodic *w) if (((W)w)->active < periodiccnt--) { periodics [((W)w)->active - 1] = periodics [periodiccnt]; - downheap ((WT *)periodics, periodiccnt, ((W)w)->active - 1); + adjustheap ((WT *)periodics, periodiccnt, ((W)w)->active - 1); } ev_stop (EV_A_ (W)w); @@ -1480,7 +1485,7 @@ void ev_check_stop (EV_P_ struct ev_check *w) { ev_clear_pending (EV_A_ (W)w); - if (ev_is_active (w)) + if (!ev_is_active (w)) return; checks [((W)w)->active - 1] = checks [--checkcnt]; @@ -1551,7 +1556,7 @@ void ev_child_stop (EV_P_ struct ev_child *w) { ev_clear_pending (EV_A_ (W)w); - if (ev_is_active (w)) + if (!ev_is_active (w)) return; wlist_del ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w);