Skip to content

Commit

Permalink
lib/ovs-atomic-gcc4+: Use 'volatile' to enforce memory access.
Browse files Browse the repository at this point in the history
Use 'volatile' to enforce a new memory access on each lockless atomic
store and read.  Without this a loop consisting of an atomic_read with
memory_order_relaxed would be simply optimized away.  Also, using
volatile is cheaper than adding a full compiler barrier (also) in that
case.

This use of a volatile cast mirrors the Linux kernel ACCESS_ONCE macro.

Without this change the more rigorous atomic test cases introduced in
a following patch will hang due to the atomic accesses being optimized
away.

Signed-off-by: Jarno Rajahalme <[email protected]>
Acked-by: Ben Pfaff <[email protected]>
  • Loading branch information
Jarno Rajahalme committed Aug 5, 2014
1 parent 9164558 commit 860f83f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/ovs-atomic-gcc4+.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ atomic_signal_fence(memory_order order)
\
if (IS_LOCKLESS_ATOMIC(*dst__)) { \
atomic_thread_fence(ORDER); \
*dst__ = src__; \
*(typeof(*DST) volatile *)dst__ = src__; \
atomic_thread_fence_if_seq_cst(ORDER); \
} else { \
atomic_store_locked(dst__, src__); \
Expand All @@ -99,7 +99,7 @@ atomic_signal_fence(memory_order order)
\
if (IS_LOCKLESS_ATOMIC(*src__)) { \
atomic_thread_fence_if_seq_cst(ORDER); \
*dst__ = *src__; \
*dst__ = *(typeof(*SRC) volatile *)src__; \
} else { \
atomic_read_locked(src__, dst__); \
} \
Expand Down

0 comments on commit 860f83f

Please sign in to comment.