[ovs-dev] [PATCH 06/18] lib/ovs-thread: Use atomic_count.

Jarno Rajahalme jrajahalme at nicira.com
Fri Aug 22 20:58:17 UTC 2014


barrier->count is used as a simple counter and is not expected the
synchronize the state of any other variable, so we can use atomic_count,
which uses relaxed atomics.

Ditto for the 'next_id' within ovsthread_wrapper().

Signed-off-by: Jarno Rajahalme <jrajahalme at nicira.com>
---
 lib/ovs-thread.c |   10 +++++-----
 lib/ovs-thread.h |    2 +-
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/lib/ovs-thread.c b/lib/ovs-thread.c
index fe6fb43..8fd5c32 100644
--- a/lib/ovs-thread.c
+++ b/lib/ovs-thread.c
@@ -266,7 +266,7 @@ void
 ovs_barrier_init(struct ovs_barrier *barrier, uint32_t size)
 {
     barrier->size = size;
-    atomic_init(&barrier->count, 0);
+    atomic_count_init(&barrier->count, 0);
     barrier->seq = seq_create();
 }
 
@@ -285,9 +285,9 @@ ovs_barrier_block(struct ovs_barrier *barrier)
     uint64_t seq = seq_read(barrier->seq);
     uint32_t orig;
 
-    atomic_add(&barrier->count, 1, &orig);
+    orig = atomic_count_inc(&barrier->count);
     if (orig + 1 == barrier->size) {
-        atomic_store(&barrier->count, 0);
+        atomic_count_set(&barrier->count, 0);
         seq_change(barrier->seq);
     }
 
@@ -310,13 +310,13 @@ struct ovsthread_aux {
 static void *
 ovsthread_wrapper(void *aux_)
 {
-    static atomic_uint next_id = ATOMIC_VAR_INIT(1);
+    static atomic_count next_id = ATOMIC_COUNT_INIT(1);
 
     struct ovsthread_aux *auxp = aux_;
     struct ovsthread_aux aux;
     unsigned int id;
 
-    atomic_add(&next_id, 1, &id);
+    id = atomic_count_inc(&next_id);
     *ovsthread_id_get() = id;
 
     aux = *auxp;
diff --git a/lib/ovs-thread.h b/lib/ovs-thread.h
index b2ac56e..962e867 100644
--- a/lib/ovs-thread.h
+++ b/lib/ovs-thread.h
@@ -34,7 +34,7 @@ struct OVS_LOCKABLE ovs_mutex {
 /* Poll-block()-able barrier similar to pthread_barrier_t. */
 struct ovs_barrier {
     uint32_t size;            /* Number of threads to wait. */
-    atomic_uint32_t count;    /* Number of threads already hit the barrier. */
+    atomic_count count;       /* Number of threads already hit the barrier. */
     struct seq *seq;
 };
 
-- 
1.7.10.4




More information about the dev mailing list