[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [RFC v1 05/12] atomic: introduce cmpxchg_bool
From: |
Eric Blake |
Subject: |
Re: [Qemu-devel] [RFC v1 05/12] atomic: introduce cmpxchg_bool |
Date: |
Fri, 3 Jun 2016 13:20:21 -0600 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 |
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