lib/ovs-rcu: evaluate argument of ovsrcu_get only once.
authorJarno Rajahalme <jrajahalme@nicira.com>
Mon, 21 Jul 2014 21:19:06 +0000 (14:19 -0700)
committerJarno Rajahalme <jrajahalme@nicira.com>
Mon, 21 Jul 2014 21:19:06 +0000 (14:19 -0700)
As ovsrcu_get() looks like a function call, it is reasonable for the
callers to expect that the arguments are evaluated only once.
CONST_CAST expands its 'POINTER' argument multiple times, and the
exact effect of this turned out to be compiler dependent.  Fix this by
expanding the macro argument before CONST_CAST, and removing
unnecessary CONST_CASTs.

VMware-BZ: #1287651

Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
lib/ovs-rcu.h

index 2c7d1ea..96b3233 100644 (file)
 #define ovsrcu_get__(TYPE, VAR, ORDER)                                  \
     ({                                                                  \
         TYPE value__;                                                   \
+        typeof(VAR) ovsrcu_var = (VAR);                                 \
                                                                         \
-        atomic_read_explicit(CONST_CAST(ATOMIC(TYPE) *, &(VAR)->p),     \
+        atomic_read_explicit(CONST_CAST(ATOMIC(TYPE) *, &ovsrcu_var->p), \
                              &value__, ORDER);                          \
                                                                         \
         value__;                                                        \
     })
 #define ovsrcu_get(TYPE, VAR) \
-    CONST_CAST(TYPE, ovsrcu_get__(TYPE, VAR, memory_order_consume))
+    ovsrcu_get__(TYPE, VAR, memory_order_consume)
 #define ovsrcu_get_protected(TYPE, VAR) \
-    CONST_CAST(TYPE, ovsrcu_get__(TYPE, VAR, memory_order_relaxed))
+    ovsrcu_get__(TYPE, VAR, memory_order_relaxed)
 
 /* 'VALUE' may be an atomic operation, which must be evaluated before
  * any of the body of the atomic_store_explicit.  Since the type of