From eb8ed438c2f4125b8c65e0470371e7992d41087a Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Tue, 23 Apr 2013 14:35:29 -0700 Subject: [PATCH] dpif: Serialize initialization. Signed-off-by: Ben Pfaff --- lib/dpif-linux.c | 7 +++++-- lib/dpif.c | 6 +++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/dpif-linux.c b/lib/dpif-linux.c index 958873cb7..831da3bbb 100644 --- a/lib/dpif-linux.c +++ b/lib/dpif-linux.c @@ -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; diff --git a/lib/dpif.c b/lib/dpif.c index e79326271..4878aac6c 100644 --- a/lib/dpif.c +++ b/lib/dpif.c @@ -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); } } -- 2.47.0