dpif: Serialize initialization.
authorBen Pfaff <blp@nicira.com>
Tue, 23 Apr 2013 21:35:29 +0000 (14:35 -0700)
committerBen Pfaff <blp@nicira.com>
Mon, 22 Jul 2013 17:53:10 +0000 (10:53 -0700)
Signed-off-by: Ben Pfaff <blp@nicira.com>
lib/dpif-linux.c
lib/dpif.c

index 958873c..831da3b 100644 (file)
@@ -1440,9 +1440,10 @@ const struct dpif_class dpif_linux_class = {
 static int
 dpif_linux_init(void)
 {
-    static int error = -1;
+    static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER;
+    static int error;
 
-    if (error < 0) {
+    if (ovsthread_once_start(&once)) {
         unsigned int ovs_vport_mcgroup;
 
         error = nl_lookup_genl_family(OVS_DATAPATH_FAMILY,
@@ -1472,6 +1473,8 @@ dpif_linux_init(void)
             nln = nln_create(NETLINK_GENERIC, ovs_vport_mcgroup,
                              dpif_linux_nln_parse, &vport);
         }
+
+        ovsthread_once_done(&once);
     }
 
     return error;
index e793262..4878aac 100644 (file)
@@ -97,15 +97,15 @@ static void log_execute_message(struct dpif *, const struct dpif_execute *,
 static void
 dp_initialize(void)
 {
-    static int status = -1;
+    static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER;
 
-    if (status < 0) {
+    if (ovsthread_once_start(&once)) {
         int i;
 
-        status = 0;
         for (i = 0; i < ARRAY_SIZE(base_dpif_classes); i++) {
             dp_register_provider(base_dpif_classes[i]);
         }
+        ovsthread_once_done(&once);
     }
 }