[ovs-dev] [PATCH 02/12] ovs-atomic: Use memory_order_relaxed for ovs_refcount.
Jarno Rajahalme
jrajahalme at nicira.com
Mon Jun 30 15:17:18 UTC 2014
Updating the reference count only requires atomicity, but no memory
ordering with respect to any other loads or stores. Avoiding the
overhead of the default memory_order_seq_cst can make these more
efficient.
Signed-off-by: Jarno Rajahalme <jrajahalme at nicira.com>
---
lib/ovs-atomic.h | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/lib/ovs-atomic.h b/lib/ovs-atomic.h
index 2452846..1a721ca 100644
--- a/lib/ovs-atomic.h
+++ b/lib/ovs-atomic.h
@@ -320,7 +320,8 @@ ovs_refcount_ref(struct ovs_refcount *refcount)
{
unsigned int old_refcount;
- atomic_add(&refcount->count, 1, &old_refcount);
+ atomic_add_explicit(&refcount->count, 1, &old_refcount,
+ memory_order_relaxed);
ovs_assert(old_refcount > 0);
}
@@ -337,7 +338,8 @@ ovs_refcount_unref(struct ovs_refcount *refcount)
{
unsigned int old_refcount;
- atomic_sub(&refcount->count, 1, &old_refcount);
+ atomic_sub_explicit(&refcount->count, 1, &old_refcount,
+ memory_order_relaxed);
ovs_assert(old_refcount > 0);
return old_refcount;
}
@@ -352,7 +354,7 @@ ovs_refcount_read(const struct ovs_refcount *refcount_)
= CONST_CAST(struct ovs_refcount *, refcount_);
unsigned int count;
- atomic_read(&refcount->count, &count);
+ atomic_read_explicit(&refcount->count, &count, memory_order_relaxed);
return count;
}
--
1.7.10.4
More information about the dev
mailing list