On 06/03/2016 01:12 PM, Alex Bennée wrote: >>> +#define atomic_bool_cmpxchg(ptr, old, new) \ >>> + ({ \ >>> + typeof(*ptr) _old = (old), _new = (new); \ >>> + bool r; \ >>> + r = __atomic_compare_exchange(ptr, &_old, &_new, false, \ >>> + __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); \ >>> + r; \ >>> + }) >>> + >>> + >> >> Could be more simple: >> >> #define atomic_bool_cmpxchg(ptr, old, new) \ >> ({ \ >> typeof(*ptr) _old = (old), _new = (new); \ >> __atomic_compare_exchange(ptr, &_old, &_new, false, \ >> __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); \ >> }) > > OK that makes sense. I'll have to ask my toolchain colleague what the > rules are for results from {} blocks.
It's a gcc extension, and the rule is that the value of the overall ({}) is the value of the last statement in the block. No need for a temporary variable 'r' if you can just use __atomic_compare_exchange() as the last statement. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature