+ ev_init (&sigev, sigcb);
+ ev_set_priority (&sigev, EV_MAXPRI);
+ }
+}
+
+void
+loop_destroy (EV_P)
+{
+ int i;
+
+#if EV_USE_KQUEUE
+ if (method == EVMETHOD_KQUEUE) kqueue_destroy (EV_A);
+#endif
+#if EV_USE_EPOLL
+ if (method == EVMETHOD_EPOLL ) epoll_destroy (EV_A);
+#endif
+#if EV_USE_POLL
+ if (method == EVMETHOD_POLL ) poll_destroy (EV_A);
+#endif
+#if EV_USE_SELECT
+ if (method == EVMETHOD_SELECT) select_destroy (EV_A);
+#endif
+
+ for (i = NUMPRI; i--; )
+ array_free (pending, [i]);
+
+ /* have to use the microsoft-never-gets-it-right macro */
+ array_free (fdchange, EMPTY);
+ array_free (timer, EMPTY);
+#if EV_PERIODICS
+ array_free (periodic, EMPTY);
+#endif
+ array_free (idle, EMPTY);
+ array_free (prepare, EMPTY);
+ array_free (check, EMPTY);
+
+ method = 0;
+}
+
+static void
+loop_fork (EV_P)
+{
+#if EV_USE_EPOLL
+ if (method == EVMETHOD_EPOLL ) epoll_fork (EV_A);
+#endif
+#if EV_USE_KQUEUE
+ if (method == EVMETHOD_KQUEUE) kqueue_fork (EV_A);
+#endif
+
+ if (ev_is_active (&sigev))
+ {
+ /* default loop */
+
+ ev_ref (EV_A);
+ ev_io_stop (EV_A_ &sigev);
+ close (sigpipe [0]);
+ close (sigpipe [1]);
+
+ while (pipe (sigpipe))
+ syserr ("(libev) error creating pipe");
+
+ siginit (EV_A);
+ }
+
+ postfork = 0;
+}
+
+#if EV_MULTIPLICITY
+struct ev_loop *
+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_ flags);
+
+ if (ev_method (EV_A))
+ return loop;
+
+ return 0;
+}
+
+void
+ev_loop_destroy (EV_P)
+{
+ loop_destroy (EV_A);
+ ev_free (loop);
+}
+
+void
+ev_loop_fork (EV_P)
+{
+ postfork = 1;
+}
+
+#endif
+
+#if EV_MULTIPLICITY
+struct ev_loop *
+#else
+int
+#endif
+ev_default_loop (unsigned int flags)
+{
+ if (sigpipe [0] == sigpipe [1])
+ if (pipe (sigpipe))
+ return 0;
+
+ if (!default_loop)
+ {
+#if EV_MULTIPLICITY
+ struct ev_loop *loop = default_loop = &default_loop_struct;
+#else
+ default_loop = 1;
+#endif
+
+ loop_init (EV_A_ flags);
+
+ if (ev_method (EV_A))