X-Git-Url: https://git.llucax.com/software/libev.git/blobdiff_plain/1b109e5d8b0948a2e7151b3820f1c4784cafeece..98d2a2bbab6df4db45d5e3a1c932ba469fd10e47:/ev.c?ds=inline diff --git a/ev.c b/ev.c index b23a70e..46c8cea 100644 --- a/ev.c +++ b/ev.c @@ -1,4 +1,6 @@ /* + * libev event processing core, watcher management + * * Copyright (c) 2007 Marc Alexander Lehmann * All rights reserved. * @@ -47,9 +49,12 @@ #include #ifndef EV_USE_MONOTONIC -# ifdef CLOCK_MONOTONIC -# define EV_USE_MONOTONIC 1 -# endif +# define EV_USE_MONOTONIC 1 +#endif + +#ifndef CLOCK_MONOTONIC +# undef EV_USE_MONOTONIC +# define EV_USE_MONOTONIC 0 #endif #ifndef EV_USE_SELECT @@ -325,14 +330,14 @@ downheap (WT *timers, int N, int k) typedef struct { struct ev_signal *head; - sig_atomic_t gotsig; + sig_atomic_t volatile gotsig; } ANSIG; static ANSIG *signals; static int signalmax; static int sigpipe [2]; -static sig_atomic_t gotsig; +static sig_atomic_t volatile gotsig; static struct ev_io sigev; static void @@ -355,7 +360,7 @@ sighandler (int signum) if (!gotsig) { gotsig = 1; - write (sigpipe [1], &gotsig, 1); + write (sigpipe [1], &signum, 1); } } @@ -363,17 +368,17 @@ static void sigcb (struct ev_io *iow, int revents) { struct ev_signal *w; - int sig; + int signum; - gotsig = 0; read (sigpipe [0], &revents, 1); + gotsig = 0; - for (sig = signalmax; sig--; ) - if (signals [sig].gotsig) + for (signum = signalmax; signum--; ) + if (signals [signum].gotsig) { - signals [sig].gotsig = 0; + signals [signum].gotsig = 0; - for (w = signals [sig].head; w; w = w->next) + for (w = signals [signum].head; w; w = w->next) event ((W)w, EV_SIGNAL); } } @@ -420,7 +425,7 @@ childcb (struct ev_signal *sw, int revents) while ((pid = waitpid (-1, &status, WNOHANG | WUNTRACED | WCONTINUED)) != -1) for (w = childs [pid & (PID_HASHSIZE - 1)]; w; w = w->next) - if (w->pid == pid || w->pid == -1) + if (w->pid == pid || !w->pid) { w->status = status; event ((W)w, EV_CHILD); @@ -491,19 +496,19 @@ int ev_init (int flags) /*****************************************************************************/ void -ev_prefork (void) +ev_fork_prepare (void) { /* nop */ } void -ev_postfork_parent (void) +ev_fork_parent (void) { /* nop */ } void -ev_postfork_child (void) +ev_fork_child (void) { #if EV_USE_EPOLL if (ev_method == EVMETHOD_EPOLL) @@ -763,11 +768,11 @@ ev_stop (W w) void ev_io_start (struct ev_io *w) { + int fd = w->fd; + if (ev_is_active (w)) return; - int fd = w->fd; - assert (("ev_io_start called with negative fd", fd >= 0)); ev_start ((W)w, 1);