On 12/19/2016 01:14 PM, Szabolcs Nagy wrote: > On 16/12/16 16:31, Stefan Liebler wrote: >> Passing a volatile pointer to the atomic macros can lead to extra stores >> and loads to stack if such a macro creates a temporary variable by using >> __typeof (*(mem)). Thus the patch passes a int pointer to the atomic macros. > > the resolution of > http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_423.htm > says that the type of a cast expression is unqualified, so > > __typeof ((__typeof (*(mem)))*(mem)) tmp = *(mem); > > would have the right type.. seems to work since gcc-5 > > https://godbolt.org/g/eS0X5b > > (looks beautiful.) > Thanks for this. I've adjusted the needed atomic-macros in include/atomic.h and use the typeof-construct "__typeof ((__typeof (*(mem)))*(mem)) tmp;". Now we can pass the volatile int pointers to the atomic-macros. See the updated patch. Okay to commit? Bye. Stefan ChangeLog: * include/atomic.h: (__atomic_val_bysize): Cast type to omit volatile qualifier. (atomic_exchange_acq): Likewise. (atomic_load_relaxed): Likewise. * nptl/pthread_spin_init.c (pthread_spin_init): Use atomic_store_relaxed. * nptl/pthread_spin_lock.c (pthread_spin_lock): Use C11-like atomic macros. * nptl/pthread_spin_trylock.c (pthread_spin_trylock): Likewise. Use an explicit test if lock is free, if new SPIN_TRYLOCK_USE_CMPXCHG_INSTEAD_OF_XCHG macro is set to one. (SPIN_TRYLOCK_USE_CMPXCHG_INSTEAD_OF_XCHG): New define. * nptl/pthread_spin_unlock.c (pthread_spin_unlock): Use atomic_store_release.