Received: from eggs.gnu.org ([2001:4830:134:3::10]:58517) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1beJXN-0001RT-WF for qemu-devel@nongnu.org; Mon, 29 Aug 2016 06:11:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1beJXJ-0008Ig-R3 for qemu-devel@nongnu.org; Mon, 29 Aug 2016 06:11:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47410) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1beJXJ-0008IR-L6 for qemu-devel@nongnu.org; Mon, 29 Aug 2016 06:11:25 -0400 References: <20160824204424.14041-1-bobby.prani@gmail.com> From: Paolo Bonzini Message-ID: Date: Mon, 29 Aug 2016 12:11:17 +0200 MIME-Version: 1.0 In-Reply-To: <20160824204424.14041-1-bobby.prani@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 1/3] atomics: Test __STDC_VERSION__ for C11 compat List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Pranith Kumar , qemu-devel@nongnu.org, "Emilio G. Cota" , =?UTF-8?Q?Alex_Benn=c3=a9e?= , Eric Blake , Markus Armbruster On 24/08/2016 22:44, Pranith Kumar wrote: > This patch tries to do the Right Thing=E2=84=A2 to test for C11 feature= s, > which is to test __STDC_VERSION__. Compilers can provide atomics even for older standards, for example: $ echo '__STDC_VERSION__' | gcc -E -x c - -std=3Dgnu99 | tail -1 199901L $ echo '__ATOMIC_RELAXED' | gcc -E -x c - -std=3Dgnu99 | tail -1 0 Which is why the patch is not using __STDC_VERSION__. Unfortunately, the C standard does not define a feature macro for atomics; it provides __STDC_NO_ATOMICS__ but it is defined backwards. Thanks, Paolo > Signed-off-by: Pranith Kumar > --- > include/qemu/atomic.h | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) >=20 > diff --git a/include/qemu/atomic.h b/include/qemu/atomic.h > index 43b0645..d313e6b 100644 > --- a/include/qemu/atomic.h > +++ b/include/qemu/atomic.h > @@ -60,7 +60,7 @@ > (unsigned short)1, = \ > (expr)+0)))))) > =20 > -#ifdef __ATOMIC_RELAXED > +#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >=3D 201112L) > /* For C11 atomic ops */ > =20 > /* Manual memory barriers > @@ -210,7 +210,7 @@ > #define atomic_and(ptr, n) ((void) __atomic_fetch_and(ptr, n, __ATOMIC= _SEQ_CST)) > #define atomic_or(ptr, n) ((void) __atomic_fetch_or(ptr, n, __ATOMIC_= SEQ_CST)) > =20 > -#else /* __ATOMIC_RELAXED */ > +#else /* __STDC_VERSION__ */ > =20 > /* > * We use GCC builtin if it's available, as that can use mfence on > @@ -405,5 +405,5 @@ > #define atomic_and(ptr, n) ((void) __sync_fetch_and_and(ptr, n)) > #define atomic_or(ptr, n) ((void) __sync_fetch_and_or(ptr, n)) > =20 > -#endif /* __ATOMIC_RELAXED */ > +#endif /* __STDC_VERSION__ */ > #endif /* QEMU_ATOMIC_H */ >=20