atomic.h: comment on use of atomic_read/set

Add some notes on the use of the relaxed atomic access helpers and their
importance for defined behaviour in C11's multi-threaded memory model.

Backports commit e653bc6b0ff645c25b8a2eb607c18a5c98b59db6 from qemu
This commit is contained in:
Alex Bennée 2018-02-26 05:03:53 -05:00 committed by Lioncash
parent f48d1fe391
commit 4046235e92
No known key found for this signature in database
GPG key ID: 4E3C3CC1031BA9C7

View file

@ -57,6 +57,12 @@ void _ReadWriteBarrier(void);
/* Weak atomic operations prevent the compiler moving other
* loads/stores past the atomic operation load/store. However there is
* no explicit memory barrier for the processor.
*
* The C11 memory model says that variables that are accessed from
* different threads should at least be done with __ATOMIC_RELAXED
* primitives or the result is undefined. Generally this has little to
* no effect on the generated code but not using the atomic primitives
* will get flagged by sanitizers as a violation.
*/
#define atomic_read(ptr) \
({ \