X-Git-Url: https://git.llucax.com/software/libev.git/blobdiff_plain/0c513fd963e79da73c7d77018523ac956a5066bd..f123911c49df152e9b27ab4df77b12a03b6abfa2:/ev.c diff --git a/ev.c b/ev.c index c77ad2a..7faa403 100644 --- a/ev.c +++ b/ev.c @@ -44,7 +44,9 @@ #include #include #include -#include +#ifndef WIN32 +# include +#endif #include #include @@ -66,6 +68,10 @@ # define EV_USE_EPOLL 0 #endif +#ifndef EV_USE_KQUEUE +# define EV_USE_KQUEUE 0 +#endif + #ifndef EV_USE_REALTIME # define EV_USE_REALTIME 1 #endif @@ -102,6 +108,9 @@ #define expect_false(expr) expect ((expr) != 0, 0) #define expect_true(expr) expect ((expr) != 0, 1) +#define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) +#define ABSPRI(w) ((w)->priority - EV_MINPRI) + typedef struct ev_watcher *W; typedef struct ev_watcher_list *WL; typedef struct ev_watcher_time *WT; @@ -195,22 +204,22 @@ typedef struct int events; } ANPENDING; -static ANPENDING *pendings; -static int pendingmax, pendingcnt; +static ANPENDING *pendings [NUMPRI]; +static int pendingmax [NUMPRI], pendingcnt [NUMPRI]; static void event (W w, int events) { if (w->pending) { - pendings [w->pending - 1].events |= events; + pendings [ABSPRI (w)][w->pending - 1].events |= events; return; } - w->pending = ++pendingcnt; - array_needsize (pendings, pendingmax, pendingcnt, ); - pendings [pendingcnt - 1].w = w; - pendings [pendingcnt - 1].events = events; + w->pending = ++pendingcnt [ABSPRI (w)]; + array_needsize (pendings [ABSPRI (w)], pendingmax [ABSPRI (w)], pendingcnt [ABSPRI (w)], ); + pendings [ABSPRI (w)][w->pending - 1].w = w; + pendings [ABSPRI (w)][w->pending - 1].events = events; } static void @@ -433,12 +442,14 @@ sigcb (struct ev_io *iow, int revents) static void siginit (void) { +#ifndef WIN32 fcntl (sigpipe [0], F_SETFD, FD_CLOEXEC); fcntl (sigpipe [1], F_SETFD, FD_CLOEXEC); /* rather than sort out wether we really need nb, set it */ fcntl (sigpipe [0], F_SETFL, O_NONBLOCK); fcntl (sigpipe [1], F_SETFL, O_NONBLOCK); +#endif ev_io_set (&sigev, sigpipe [0], EV_READ); ev_io_start (&sigev); @@ -460,6 +471,8 @@ static int checkmax, checkcnt; static struct ev_child *childs [PID_HASHSIZE]; static struct ev_signal childev; +#ifndef WIN32 + #ifndef WCONTINUED # define WCONTINUED 0 #endif @@ -479,8 +492,13 @@ childcb (struct ev_signal *sw, int revents) } } +#endif + /*****************************************************************************/ +#if EV_USE_KQUEUE +# include "ev_kqueue.c" +#endif #if EV_USE_EPOLL # include "ev_epoll.c" #endif @@ -538,6 +556,9 @@ int ev_init (int methods) methods = EVMETHOD_ANY; ev_method = 0; +#if EV_USE_KQUEUE + if (!ev_method && (methods & EVMETHOD_KQUEUE)) kqueue_init (methods); +#endif #if EV_USE_EPOLL if (!ev_method && (methods & EVMETHOD_EPOLL )) epoll_init (methods); #endif @@ -553,8 +574,10 @@ int ev_init (int methods) ev_watcher_init (&sigev, sigcb); siginit (); +#ifndef WIN32 ev_signal_init (&childev, childcb, SIGCHLD); ev_signal_start (&childev); +#endif } } @@ -595,16 +618,19 @@ ev_fork_child (void) static void call_pending (void) { - while (pendingcnt) - { - ANPENDING *p = pendings + --pendingcnt; + int pri; - if (p->w) - { - p->w->pending = 0; - p->w->cb (p->w, p->events); - } - } + for (pri = NUMPRI; pri--; ) + while (pendingcnt [pri]) + { + ANPENDING *p = pendings [pri] + --pendingcnt [pri]; + + if (p->w) + { + p->w->pending = 0; + p->w->cb (p->w, p->events); + } + } } static void @@ -846,7 +872,7 @@ ev_clear_pending (W w) { if (w->pending) { - pendings [w->pending - 1].w = 0; + pendings [ABSPRI (w)][w->pending - 1].w = 0; w->pending = 0; } } @@ -854,6 +880,9 @@ ev_clear_pending (W w) static void ev_start (W w, int active) { + if (w->priority < EV_MINPRI) w->priority = EV_MINPRI; + if (w->priority > EV_MAXPRI) w->priority = EV_MAXPRI; + w->active = active; }