+void evidle_start (struct ev_idle *w)
+{
+ if (ev_is_active (w))
+ return;
+
+ ev_start ((W)w, ++idlecnt);
+ array_needsize (idles, idlemax, idlecnt, );
+ idles [idlecnt - 1] = w;
+}
+
+void evidle_stop (struct ev_idle *w)
+{
+ ev_clear ((W)w);
+ if (ev_is_active (w))
+ return;
+
+ idles [w->active - 1] = idles [--idlecnt];
+ ev_stop ((W)w);
+}
+
+void evprepare_start (struct ev_prepare *w)
+{
+ if (ev_is_active (w))
+ return;
+
+ ev_start ((W)w, ++preparecnt);
+ array_needsize (prepares, preparemax, preparecnt, );
+ prepares [preparecnt - 1] = w;
+}
+
+void evprepare_stop (struct ev_prepare *w)
+{
+ ev_clear ((W)w);
+ if (ev_is_active (w))
+ return;
+
+ prepares [w->active - 1] = prepares [--preparecnt];
+ ev_stop ((W)w);
+}
+
+void evcheck_start (struct ev_check *w)
+{
+ if (ev_is_active (w))
+ return;
+
+ ev_start ((W)w, ++checkcnt);
+ array_needsize (checks, checkmax, checkcnt, );
+ checks [checkcnt - 1] = w;
+}
+
+void evcheck_stop (struct ev_check *w)
+{
+ ev_clear ((W)w);
+ if (ev_is_active (w))
+ return;
+
+ checks [w->active - 1] = checks [--checkcnt];
+ ev_stop ((W)w);
+}
+
+/*****************************************************************************/
+
+struct ev_once
+{
+ struct ev_io io;
+ struct ev_timer to;
+ void (*cb)(int revents, void *arg);
+ void *arg;
+};
+
+static void
+once_cb (struct ev_once *once, int revents)
+{
+ void (*cb)(int revents, void *arg) = once->cb;
+ void *arg = once->arg;
+
+ evio_stop (&once->io);
+ evtimer_stop (&once->to);
+ free (once);
+
+ cb (revents, arg);
+}
+
+static void
+once_cb_io (struct ev_io *w, int revents)
+{
+ once_cb ((struct ev_once *)(((char *)w) - offsetof (struct ev_once, io)), revents);
+}
+
+static void
+once_cb_to (struct ev_timer *w, int revents)
+{
+ once_cb ((struct ev_once *)(((char *)w) - offsetof (struct ev_once, to)), revents);
+}
+
+void
+ev_once (int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg)
+{
+ struct ev_once *once = malloc (sizeof (struct ev_once));
+
+ if (!once)
+ cb (EV_ERROR, arg);
+ else
+ {
+ once->cb = cb;
+ once->arg = arg;
+
+ evw_init (&once->io, once_cb_io);
+
+ if (fd >= 0)
+ {
+ evio_set (&once->io, fd, events);
+ evio_start (&once->io);
+ }
+
+ evw_init (&once->to, once_cb_to);
+
+ if (timeout >= 0.)
+ {
+ evtimer_set (&once->to, timeout, 0.);
+ evtimer_start (&once->to);
+ }
+ }
+}
+