X-Git-Url: https://git.llucax.com/software/libev.git/blobdiff_plain/2dff0867c6069c41ede598cd78bb2d5223fde025..7e305734bf37cb00b5be4f32a80bccdf83c768b8:/ev.c diff --git a/ev.c b/ev.c index 89c0929..ce8987f 100644 --- a/ev.c +++ b/ev.c @@ -97,10 +97,15 @@ extern "C" { #ifndef EV_USE_SELECT # define EV_USE_SELECT 1 +# define EV_SELECT_USE_FD_SET 1 #endif #ifndef EV_USE_POLL -# define EV_USE_POLL 0 /* poll is usually slower than select, and not as well tested */ +# ifdef _WIN32 +# define EV_USE_POLL 0 +# else +# define EV_USE_POLL 1 +# endif #endif #ifndef EV_USE_EPOLL @@ -117,6 +122,12 @@ extern "C" { /**/ +/* darwin simply cannot be helped */ +#ifdef __APPLE__ +# undef EV_USE_POLL +# undef EV_USE_KQUEUE +#endif + #ifndef CLOCK_MONOTONIC # undef EV_USE_MONOTONIC # define EV_USE_MONOTONIC 0 @@ -301,7 +312,7 @@ ev_now (EV_P) } #endif -#define array_roundsize(type,n) ((n) | 4 & ~3) +#define array_roundsize(type,n) (((n) | 4) & ~3) #define array_needsize(type,base,cur,cnt,init) \ if (expect_false ((cnt) > cur)) \ @@ -744,7 +755,7 @@ ev_method (EV_P) } static void -loop_init (EV_P_ int methods) +loop_init (EV_P_ unsigned int flags) { if (!method) { @@ -761,24 +772,24 @@ loop_init (EV_P_ int methods) now_floor = mn_now; rtmn_diff = ev_rt_now - mn_now; - if (methods == EVMETHOD_AUTO) - if (!enable_secure () && getenv ("LIBEV_METHODS")) - methods = atoi (getenv ("LIBEV_METHODS")); - else - methods = EVMETHOD_ANY; + if (!(flags & EVMETHOD_NOENV) && !enable_secure () && getenv ("LIBEV_FLAGS")) + flags = atoi (getenv ("LIBEV_FLAGS")); + + if (!(flags & 0x0000ffff)) + flags |= 0x0000ffff; method = 0; #if EV_USE_KQUEUE - if (!method && (methods & EVMETHOD_KQUEUE)) method = kqueue_init (EV_A_ methods); + if (!method && (flags & EVMETHOD_KQUEUE)) method = kqueue_init (EV_A_ flags); #endif #if EV_USE_EPOLL - if (!method && (methods & EVMETHOD_EPOLL )) method = epoll_init (EV_A_ methods); + if (!method && (flags & EVMETHOD_EPOLL )) method = epoll_init (EV_A_ flags); #endif #if EV_USE_POLL - if (!method && (methods & EVMETHOD_POLL )) method = poll_init (EV_A_ methods); + if (!method && (flags & EVMETHOD_POLL )) method = poll_init (EV_A_ flags); #endif #if EV_USE_SELECT - if (!method && (methods & EVMETHOD_SELECT)) method = select_init (EV_A_ methods); + if (!method && (flags & EVMETHOD_SELECT)) method = select_init (EV_A_ flags); #endif ev_init (&sigev, sigcb); @@ -850,13 +861,13 @@ loop_fork (EV_P) #if EV_MULTIPLICITY struct ev_loop * -ev_loop_new (int methods) +ev_loop_new (unsigned int flags) { struct ev_loop *loop = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); memset (loop, 0, sizeof (struct ev_loop)); - loop_init (EV_A_ methods); + loop_init (EV_A_ flags); if (ev_method (EV_A)) return loop; @@ -884,7 +895,7 @@ struct ev_loop * #else int #endif -ev_default_loop (int methods) +ev_default_loop (unsigned int methods) { if (sigpipe [0] == sigpipe [1]) if (pipe (sigpipe)) @@ -1022,8 +1033,7 @@ periodics_reify (EV_P) /* first reschedule or stop timer */ if (w->reschedule_cb) { - ev_tstamp at = ((WT)w)->at = w->reschedule_cb (w, ev_rt_now + 0.0001); - + ((WT)w)->at = w->reschedule_cb (w, ev_rt_now + 0.0001); assert (("ev_periodic reschedule callback returned time in the past", ((WT)w)->at > ev_rt_now)); downheap ((WT *)periodics, periodiccnt, 0); }