+static void
+loop_destroy (EV_P)
+{
+ int i;
+
+#if EV_USE_PORT
+ if (method == EVMETHOD_PORT ) port_destroy (EV_A);
+#endif
+#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, EMPTY0);
+ array_free (timer, EMPTY0);
+#if EV_PERIODICS
+ array_free (periodic, EMPTY0);
+#endif
+ array_free (idle, EMPTY0);
+ array_free (prepare, EMPTY0);
+ array_free (check, EMPTY0);
+
+ method = 0;
+}
+
+static void
+loop_fork (EV_P)
+{
+#if EV_USE_PORT
+ if (method == EVMETHOD_PORT ) port_fork (EV_A);
+#endif
+#if EV_USE_KQUEUE
+ if (method == EVMETHOD_KQUEUE) kqueue_fork (EV_A);
+#endif
+#if EV_USE_EPOLL
+ if (method == EVMETHOD_EPOLL ) epoll_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);