Compiler implementations may provide sub-optimal support for
a memory_order passed in as a run-time value
(ref. https://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html).

Document that OVS atomics require the memory order to be passed in as
a compile-time constant, and modify lib/cmap.c to comply with this.

Signed-off-by: Jarno Rajahalme <jrajaha...@nicira.com>
---
 lib/cmap.c       |   18 +++++++++++-------
 lib/ovs-atomic.h |    3 +++
 2 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/lib/cmap.c b/lib/cmap.c
index ba744cc..60629b1 100644
--- a/lib/cmap.c
+++ b/lib/cmap.c
@@ -163,19 +163,23 @@ struct cmap_impl {
 };
 BUILD_ASSERT_DECL(sizeof(struct cmap_impl) == CACHE_LINE_SIZE);
 
-static uint32_t cmap_get_hash__(const atomic_uint32_t *hash,
-                                memory_order order)
+static inline uint32_t cmap_get_hash(const atomic_uint32_t *hash)
 {
     uint32_t hash__;
 
-    atomic_read_explicit(CONST_CAST(ATOMIC(uint32_t) *, hash), &hash__, order);
+    atomic_read_explicit(CONST_CAST(ATOMIC(uint32_t) *, hash), &hash__,
+                         memory_order_acquire);
     return hash__;
 }
 
-#define cmap_get_hash(HASH) \
-    cmap_get_hash__(HASH, memory_order_acquire)
-#define cmap_get_hash_protected(HASH) \
-    cmap_get_hash__(HASH, memory_order_relaxed)
+static inline uint32_t cmap_get_hash_protected(const atomic_uint32_t *hash)
+{
+    uint32_t hash__;
+
+    atomic_read_explicit(CONST_CAST(ATOMIC(uint32_t) *, hash), &hash__,
+                         memory_order_relaxed);
+    return hash__;
+}
 
 static struct cmap_impl *cmap_rehash(struct cmap *, uint32_t mask);
 
diff --git a/lib/ovs-atomic.h b/lib/ovs-atomic.h
index a76fe14..2633e5e 100644
--- a/lib/ovs-atomic.h
+++ b/lib/ovs-atomic.h
@@ -175,6 +175,9 @@
  *        whole system, providing a total order for stores an all atomic
  *        variables.
  *
+ * OVS atomics require the memory_order to be passed as a compile-time constant
+ * value.
+ *
  * The following functions insert explicit barriers.  Most of the other atomic
  * functions also include barriers.
  *
-- 
1.7.10.4

_______________________________________________
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev

Reply via email to