vmm: Use VMM_CTL to set VMM flags (XCC)
[akaros.git] / user / iplib / epoll.c
index 85fa52f..9339a58 100644 (file)
@@ -34,6 +34,7 @@
 #include <parlib/uthread.h>
 #include <parlib/timing.h>
 #include <parlib/slab.h>
+#include <parlib/assert.h>
 #include <sys/user_fd.h>
 #include <sys/close_cb.h>
 #include <stdio.h>
@@ -63,13 +64,13 @@ static struct kmem_cache *ep_alarms_cache;
 struct epoll_ctlr {
        TAILQ_ENTRY(epoll_ctlr)         link;
        struct event_queue                      *ceq_evq;
-       uth_mutex_t                                     mtx;
+       uth_mutex_t                                     *mtx;
        struct user_fd                          ufd;
 };
 
 TAILQ_HEAD(epoll_ctlrs, epoll_ctlr);
 static struct epoll_ctlrs all_ctlrs = TAILQ_HEAD_INITIALIZER(all_ctlrs);
-static uth_mutex_t ctlrs_mtx;
+static uth_mutex_t *ctlrs_mtx;
 
 /* There's some bookkeeping we need to maintain on every FD.  Right now, the FD
  * is the index into the CEQ event array, so we can just hook this into the user
@@ -253,14 +254,15 @@ static void epoll_fd_closed(int fd)
        uth_mutex_unlock(ctlrs_mtx);
 }
 
-static void ep_alarm_ctor(void *obj, size_t unused)
+static int ep_alarm_ctor(void *obj, void *priv, int flags)
 {
        struct ep_alarm *ep_a = (struct ep_alarm*)obj;
 
        ep_a->alarm_evq = ep_get_alarm_evq();
+       return 0;
 }
 
-static void ep_alarm_dtor(void *obj, size_t unused)
+static void ep_alarm_dtor(void *obj, void *priv)
 {
        struct ep_alarm *ep_a = (struct ep_alarm*)obj;
 
@@ -272,7 +274,7 @@ static void ep_alarm_dtor(void *obj, size_t unused)
        ep_put_alarm_evq(ep_a->alarm_evq);
 }
 
-static void epoll_init(void)
+static void epoll_init(void *arg)
 {
        static struct close_cb epoll_close_cb = {.func = epoll_fd_closed};
 
@@ -281,7 +283,7 @@ static void epoll_init(void)
        ep_alarms_cache = kmem_cache_create("epoll alarms",
                                            sizeof(struct ep_alarm),
                                            __alignof__(sizeof(struct ep_alarm)), 0,
-                                           ep_alarm_ctor, ep_alarm_dtor);
+                                           ep_alarm_ctor, ep_alarm_dtor, NULL);
        assert(ep_alarms_cache);
 }
 
@@ -289,8 +291,9 @@ int epoll_create(int size)
 {
        int fd;
        struct epoll_ctlr *ep;
+       static parlib_once_t once = PARLIB_ONCE_INIT;
 
-       run_once(epoll_init());
+       parlib_run_once(&once, epoll_init, NULL);
        /* good thing the arg is a signed int... */
        if (size < 0) {
                errno = EINVAL;