+ {
+ base->head = 0;
+ base->gotsig = 0;
+
+ ++base;
+ }
+}
+
+static void
+sighandler (int signum)
+{
+ signals [signum - 1].gotsig = 1;
+
+ if (!gotsig)
+ {
+ int old_errno = errno;
+ gotsig = 1;
+ write (sigpipe [1], &signum, 1);
+ errno = old_errno;
+ }
+}
+
+static void
+sigcb (EV_P_ struct ev_io *iow, int revents)
+{
+ struct ev_watcher_list *w;
+ int signum;
+
+ read (sigpipe [0], &revents, 1);
+ gotsig = 0;
+
+ for (signum = signalmax; signum--; )
+ if (signals [signum].gotsig)
+ {
+ signals [signum].gotsig = 0;
+
+ for (w = signals [signum].head; w; w = w->next)
+ event (EV_A_ (W)w, EV_SIGNAL);
+ }
+}
+
+static void
+siginit (EV_P)
+{
+#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);
+ ev_unref (EV_A); /* child watcher should not keep loop alive */
+}
+
+/*****************************************************************************/
+
+static struct ev_idle **idles;
+static int idlemax, idlecnt;
+
+static struct ev_prepare **prepares;
+static int preparemax, preparecnt;
+
+static struct ev_check **checks;
+static int checkmax, checkcnt;
+
+/*****************************************************************************/
+
+static struct ev_child *childs [PID_HASHSIZE];
+static struct ev_signal childev;
+
+#ifndef WIN32
+
+#ifndef WCONTINUED
+# define WCONTINUED 0
+#endif
+
+static void
+child_reap (EV_P_ struct ev_signal *sw, int chain, int pid, int status)
+{
+ struct ev_child *w;
+
+ for (w = (struct ev_child *)childs [chain & (PID_HASHSIZE - 1)]; w; w = (struct ev_child *)((WL)w)->next)
+ if (w->pid == pid || !w->pid)
+ {
+ w->priority = sw->priority; /* need to do it *now* */
+ w->rpid = pid;
+ w->rstatus = status;
+ event (EV_A_ (W)w, EV_CHILD);
+ }