+void noinline
+ev_io_start (EV_P_ ev_io *w)
+{
+ int fd = w->fd;
+
+ if (expect_false (ev_is_active (w)))
+ return;
+
+ assert (("ev_io_start called with negative fd", fd >= 0));
+
+ ev_start (EV_A_ (W)w, 1);
+ array_needsize (ANFD, anfds, anfdmax, fd + 1, anfds_init);
+ wlist_add ((WL *)&anfds[fd].head, (WL)w);
+
+ fd_change (EV_A_ fd);
+}
+
+void noinline
+ev_io_stop (EV_P_ ev_io *w)
+{
+ clear_pending (EV_A_ (W)w);
+ if (expect_false (!ev_is_active (w)))
+ return;
+
+ assert (("ev_io_start called with illegal fd (must stay constant after start!)", w->fd >= 0 && w->fd < anfdmax));
+
+ wlist_del ((WL *)&anfds[w->fd].head, (WL)w);
+ ev_stop (EV_A_ (W)w);
+
+ fd_change (EV_A_ w->fd);
+}
+
+void noinline
+ev_timer_start (EV_P_ ev_timer *w)
+{
+ if (expect_false (ev_is_active (w)))
+ return;
+
+ ((WT)w)->at += mn_now;
+
+ assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.));
+
+ ev_start (EV_A_ (W)w, ++timercnt);
+ array_needsize (ev_timer *, timers, timermax, timercnt, EMPTY2);
+ timers [timercnt - 1] = w;
+ upheap ((WT *)timers, timercnt - 1);
+
+ /*assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w));*/
+}
+
+void noinline
+ev_timer_stop (EV_P_ ev_timer *w)
+{
+ clear_pending (EV_A_ (W)w);
+ if (expect_false (!ev_is_active (w)))
+ return;
+
+ assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w));
+
+ {
+ int active = ((W)w)->active;
+
+ if (expect_true (--active < --timercnt))
+ {
+ timers [active] = timers [timercnt];
+ adjustheap ((WT *)timers, timercnt, active);
+ }
+ }
+
+ ((WT)w)->at -= mn_now;
+
+ ev_stop (EV_A_ (W)w);
+}
+
+void noinline
+ev_timer_again (EV_P_ ev_timer *w)
+{
+ if (ev_is_active (w))
+ {
+ if (w->repeat)
+ {
+ ((WT)w)->at = mn_now + w->repeat;
+ adjustheap ((WT *)timers, timercnt, ((W)w)->active - 1);
+ }
+ else
+ ev_timer_stop (EV_A_ w);
+ }
+ else if (w->repeat)
+ {
+ w->at = w->repeat;
+ ev_timer_start (EV_A_ w);
+ }
+}
+
+#if EV_PERIODIC_ENABLE
+void noinline
+ev_periodic_start (EV_P_ ev_periodic *w)
+{
+ if (expect_false (ev_is_active (w)))
+ return;
+
+ if (w->reschedule_cb)
+ ((WT)w)->at = w->reschedule_cb (w, ev_rt_now);
+ else if (w->interval)
+ {
+ assert (("ev_periodic_start called with negative interval value", w->interval >= 0.));
+ /* this formula differs from the one in periodic_reify because we do not always round up */
+ ((WT)w)->at += ceil ((ev_rt_now - ((WT)w)->at) / w->interval) * w->interval;
+ }
+
+ ev_start (EV_A_ (W)w, ++periodiccnt);
+ array_needsize (ev_periodic *, periodics, periodicmax, periodiccnt, EMPTY2);
+ periodics [periodiccnt - 1] = w;
+ upheap ((WT *)periodics, periodiccnt - 1);
+
+ /*assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w));*/
+}
+
+void noinline
+ev_periodic_stop (EV_P_ ev_periodic *w)
+{
+ clear_pending (EV_A_ (W)w);
+ if (expect_false (!ev_is_active (w)))
+ return;
+
+ assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w));
+
+ {
+ int active = ((W)w)->active;
+
+ if (expect_true (--active < --periodiccnt))
+ {
+ periodics [active] = periodics [periodiccnt];
+ adjustheap ((WT *)periodics, periodiccnt, active);
+ }
+ }
+
+ ev_stop (EV_A_ (W)w);
+}
+
+void noinline
+ev_periodic_again (EV_P_ ev_periodic *w)
+{
+ /* TODO: use adjustheap and recalculation */
+ ev_periodic_stop (EV_A_ w);
+ ev_periodic_start (EV_A_ w);
+}
+#endif
+
+#ifndef SA_RESTART
+# define SA_RESTART 0
+#endif
+
+void noinline
+ev_signal_start (EV_P_ ev_signal *w)
+{
+#if EV_MULTIPLICITY
+ assert (("signal watchers are only supported in the default loop", loop == ev_default_loop_ptr));
+#endif
+ if (expect_false (ev_is_active (w)))
+ return;
+
+ assert (("ev_signal_start called with illegal signal number", w->signum > 0));
+
+ ev_start (EV_A_ (W)w, 1);
+ array_needsize (ANSIG, signals, signalmax, w->signum, signals_init);
+ wlist_add ((WL *)&signals [w->signum - 1].head, (WL)w);
+
+ if (!((WL)w)->next)
+ {
+#if _WIN32
+ signal (w->signum, sighandler);
+#else
+ struct sigaction sa;
+ sa.sa_handler = sighandler;
+ sigfillset (&sa.sa_mask);
+ sa.sa_flags = SA_RESTART; /* if restarting works we save one iteration */
+ sigaction (w->signum, &sa, 0);
+#endif
+ }
+}
+
+void noinline
+ev_signal_stop (EV_P_ ev_signal *w)
+{
+ clear_pending (EV_A_ (W)w);
+ if (expect_false (!ev_is_active (w)))
+ return;
+
+ wlist_del ((WL *)&signals [w->signum - 1].head, (WL)w);
+ ev_stop (EV_A_ (W)w);
+
+ if (!signals [w->signum - 1].head)
+ signal (w->signum, SIG_DFL);
+}
+
+void
+ev_child_start (EV_P_ ev_child *w)
+{
+#if EV_MULTIPLICITY
+ assert (("child watchers are only supported in the default loop", loop == ev_default_loop_ptr));
+#endif
+ if (expect_false (ev_is_active (w)))
+ return;
+
+ ev_start (EV_A_ (W)w, 1);
+ wlist_add ((WL *)&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w);
+}
+
+void
+ev_child_stop (EV_P_ ev_child *w)