lib/ovs-atomic-gcc4+: Use 'volatile' to enforce memory access.
authorJarno Rajahalme <jrajahalme@nicira.com>
Tue, 5 Aug 2014 20:51:19 +0000 (13:51 -0700)
committerJarno Rajahalme <jrajahalme@nicira.com>
Tue, 5 Aug 2014 20:51:19 +0000 (13:51 -0700)
commit860f83f3f290aabddc033548848c953dc7b8dd0f
tree9648201c2590daab2e9a0872b7cb8ba940881488
parent91645580722ca44f1617bd3d343f054fc7b4967b
lib/ovs-atomic-gcc4+: Use 'volatile' to enforce memory access.

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 <jrajahalme@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
lib/ovs-atomic-gcc4+.h