Re: [PATCH 0/24] make atomic_read() behave consistently across all architectures
From: Segher Boessenkool <hidden>
Date: 2007-08-16 20:52:34
Also in:
lkml, netdev
From: Segher Boessenkool <hidden>
Date: 2007-08-16 20:52:34
Also in:
lkml, netdev
Note that "volatile" is a type-qualifier, not a type itself, so a cast of the _object_ itself to a qualified-type i.e. (volatile int) would not make the access itself volatile-qualified.
There is no such thing as "volatile-qualified access" defined anywhere; there only is the concept of a "volatile-qualified *object*".
To serve our purposes, it is necessary for us to take the address of this (non-volatile) object, cast the resulting _pointer_ to the corresponding volatile-qualified pointer-type, and then dereference it. This makes that particular _access_ be volatile-qualified, without the object itself being such. Also note that the (dereferenced) result is also a valid lvalue and hence can be used in "*(volatile int *)&a = b;" kind of construction (which we use for the atomic_set case).
There is a quite convincing argument that such an access _is_ an access to a volatile object; see GCC PR21568 comment #9. This probably isn't the last word on the matter though... Segher