lib: Expose struct ovs_list definition in <openvswitch/list.h>
[cascardo/ovs.git] / lib / ovs-thread.c
index 955c1c1..3dd0ed6 100644 (file)
@@ -367,17 +367,23 @@ bool
 ovsthread_once_start__(struct ovsthread_once *once)
 {
     ovs_mutex_lock(&once->mutex);
-    if (!ovsthread_once_is_done__(once)) {
-        return false;
+    /* Mutex synchronizes memory, so we get the current value of 'done'. */
+    if (!once->done) {
+        return true;
     }
     ovs_mutex_unlock(&once->mutex);
-    return true;
+    return false;
 }
 
 void
 ovsthread_once_done(struct ovsthread_once *once)
 {
-    atomic_store(&once->done, true);
+    /* We need release semantics here, so that the following store may not
+     * be moved ahead of any of the preceding initialization operations.
+     * A release atomic_thread_fence provides that prior memory accesses
+     * will not be reordered to take place after the following store. */
+    atomic_thread_fence(memory_order_release);
+    once->done = true;
     ovs_mutex_unlock(&once->mutex);
 }
 \f
@@ -585,7 +591,7 @@ count_cpu_cores(void)
 
 /* A piece of thread-specific data. */
 struct ovsthread_key {
-    struct list list_node;      /* In 'inuse_keys' or 'free_keys'. */
+    struct ovs_list list_node;  /* In 'inuse_keys' or 'free_keys'. */
     void (*destructor)(void *); /* Called at thread exit. */
 
     /* Indexes into the per-thread array in struct ovsthread_key_slots.
@@ -595,7 +601,7 @@ struct ovsthread_key {
 
 /* Per-thread data structure. */
 struct ovsthread_key_slots {
-    struct list list_node;      /* In 'slots_list'. */
+    struct ovs_list list_node;  /* In 'slots_list'. */
     void **p1[L1_SIZE];
 };
 
@@ -614,15 +620,15 @@ static struct ovs_mutex key_mutex = OVS_MUTEX_INITIALIZER;
  *
  * Together, 'inuse_keys' and 'free_keys' hold an ovsthread_key for every index
  * from 0 to n_keys - 1, inclusive. */
-static struct list inuse_keys OVS_GUARDED_BY(key_mutex)
-    = LIST_INITIALIZER(&inuse_keys);
-static struct list free_keys OVS_GUARDED_BY(key_mutex)
-    = LIST_INITIALIZER(&free_keys);
+static struct ovs_list inuse_keys OVS_GUARDED_BY(key_mutex)
+    = OVS_LIST_INITIALIZER(&inuse_keys);
+static struct ovs_list free_keys OVS_GUARDED_BY(key_mutex)
+    = OVS_LIST_INITIALIZER(&free_keys);
 static unsigned int n_keys OVS_GUARDED_BY(key_mutex);
 
 /* All existing struct ovsthread_key_slots. */
-static struct list slots_list OVS_GUARDED_BY(key_mutex)
-    = LIST_INITIALIZER(&slots_list);
+static struct ovs_list slots_list OVS_GUARDED_BY(key_mutex)
+    = OVS_LIST_INITIALIZER(&slots_list);
 
 static void *
 clear_slot(struct ovsthread_key_slots *slots, unsigned int index)