+static void waker_consume(struct uloop_fd *fd, unsigned int events)
+{
+ char buf[4];
+
+ while (read(fd->fd, buf, 4) > 0)
+ ;
+}
+
+static int waker_pipe = -1;
+static struct uloop_fd waker_fd = {
+ .fd = -1,
+ .cb = waker_consume,
+};
+
+static void waker_init_fd(int fd)
+{
+ fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
+ fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK);
+}
+
+static int waker_init(void)
+{
+ int fds[2];
+
+ if (waker_pipe >= 0)
+ return 0;
+
+ if (pipe(fds) < 0)
+ return -1;
+
+ waker_init_fd(fds[0]);
+ waker_init_fd(fds[1]);
+ waker_pipe = fds[1];
+
+ waker_fd.fd = fds[0];
+ waker_fd.cb = waker_consume;
+ uloop_fd_add(&waker_fd, ULOOP_READ);
+
+ return 0;
+}
+
+int uloop_init(void)
+{
+ if (uloop_init_pollfd() < 0)
+ return -1;
+
+ if (waker_init() < 0) {
+ uloop_done();
+ return -1;
+ }
+
+ return 0;
+}
+