From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57512) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8udy-0004no-2U for qemu-devel@nongnu.org; Fri, 03 Jun 2016 15:20:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b8uds-0008Sk-5N for qemu-devel@nongnu.org; Fri, 03 Jun 2016 15:20:29 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36102) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8udr-0008SV-Sr for qemu-devel@nongnu.org; Fri, 03 Jun 2016 15:20:24 -0400 References: <1460730231-1184-1-git-send-email-alex.bennee@linaro.org> <1460730231-1184-7-git-send-email-alex.bennee@linaro.org> <5751B411.8010808@gmail.com> <87h9da6q8j.fsf@linaro.org> From: Eric Blake Message-ID: <5751D875.2080707@redhat.com> Date: Fri, 3 Jun 2016 13:20:21 -0600 MIME-Version: 1.0 In-Reply-To: <87h9da6q8j.fsf@linaro.org> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="wWjk49o6HjmDGJJgj7xaqr6r32c1AXNGk" Subject: Re: [Qemu-devel] [RFC v1 05/12] atomic: introduce cmpxchg_bool List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?UTF-8?Q?Alex_Benn=c3=a9e?= , Sergey Fedorov Cc: mttcg@greensocs.com, peter.maydell@linaro.org, claudio.fontana@huawei.com, jan.kiszka@siemens.com, mark.burton@greensocs.com, qemu-devel@nongnu.org, a.rigo@virtualopensystems.com, cota@braap.org, pbonzini@redhat.com, rth@twiddle.net, fred.konrad@greensocs.com This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --wWjk49o6HjmDGJJgj7xaqr6r32c1AXNGk Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 06/03/2016 01:12 PM, Alex Benn=C3=A9e wrote: >>> +#define atomic_bool_cmpxchg(ptr, old, new) = \ >>> + ({ = \ >>> + typeof(*ptr) _old =3D (old), _new =3D (new); = \ >>> + bool r; = \ >>> + r =3D __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 =3D (old), _new =3D (new); = \ >> __atomic_compare_exchange(ptr, &_old, &_new, false, = \ >> __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); = \ >> }) >=20 > 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. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --wWjk49o6HjmDGJJgj7xaqr6r32c1AXNGk Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJXUdh1AAoJEKeha0olJ0NqoVIIAJVytjSN1QTNqj0LSvDlf4UL bn3E776b6IXoitrSOg2AWdAwgO5eBmKRT1QpVNiuKC3nfSDmlp9ySnYdmbacl4+N O7DF50z2IQURNAN3TYhXEFi00DXTqgVA40POxLKsB+JJWeQ8hxCqVpzJ8AEadA3G 8XhF5m6dM5zcTJi8ItzYrpOI31vvzanUEoRQlD6VE4DWJTyXbdvNL4d3QIY5D+K0 DQjhxJ8vwVociZPqEGIW/gUoRWLYhBa7wfqJICGs+hQzNtbongITKJ4dJP+j9ukY h9Rz2aXB27vRt8LJRa7Dslyi3aKxPW2kPUquCF35w/Bu3dMHEVY1rUciOodmP0U= =djsE -----END PGP SIGNATURE----- --wWjk49o6HjmDGJJgj7xaqr6r32c1AXNGk--