From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44553) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UumNS-0007BG-Cv for qemu-devel@nongnu.org; Thu, 04 Jul 2013 12:27:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UumNR-0000N3-8p for qemu-devel@nongnu.org; Thu, 04 Jul 2013 12:27:26 -0400 Received: from goliath.siemens.de ([192.35.17.28]:15605) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UumNQ-0000Ml-VA for qemu-devel@nongnu.org; Thu, 04 Jul 2013 12:27:25 -0400 Message-ID: <51D5A261.8050702@siemens.com> Date: Thu, 04 Jul 2013 18:27:13 +0200 From: Jan Kiszka MIME-Version: 1.0 References: <1372671341-19855-1-git-send-email-stefanha@redhat.com> <1372671341-19855-3-git-send-email-stefanha@redhat.com> <51D15699.6060708@redhat.com> In-Reply-To: <51D15699.6060708@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 2/2] qemu-thread: add TLS wrappers List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: Peter Maydell , Anthony Liguori , Ed Maste , qemu-devel@nongnu.org, Stefan Hajnoczi On 2013-07-01 12:14, Paolo Bonzini wrote: > Il 01/07/2013 11:54, Peter Maydell ha scritto: >> On 1 July 2013 10:35, Stefan Hajnoczi wrote: >>> From: Paolo Bonzini >>> >>> Fast TLS is not available on some platforms, but it is always nice to >>> use it. This wrapper implementation falls back to pthread_get/setspe= cific >>> on POSIX systems that lack __thread, but uses the dynamic linker's TL= S >>> support on Linux and Windows. >>> >>> The user shall call tls_alloc_foo() in every thread that needs to acc= ess >>> the variable---exactly once and before any access. foo is the name o= f >>> the variable as passed to DECLARE_TLS and DEFINE_TLS. Then, >>> tls_get_foo() will return the address of the variable. It is guarant= eed >>> to remain the same across the lifetime of a thread, so you can cache = it. >> >>> ########################################## >>> +# check for TLS runtime >>> + >>> +# Some versions of mingw include the "magic" definitions that make >>> +# TLS work, some don't. Check for it. >>> + >>> +if test "$mingw32" =3D yes; then >>> + cat > $TMPC << EOF >>> +int main(void) {} >> >> Execution falls off the end of function without returning a value >> (I would expect the compiler to issue a warning about this.) >> >>> +#ifndef QEMU_TLS_H >>> +#define QEMU_TLS_H >>> + >>> +#if defined __linux__ >>> +#define DECLARE_TLS(type, x) \ >>> +extern __thread typeof(type) x; \ >>> + \ >>> +static inline typeof(type) *tls_get_##x(void) \ >>> +{ \ >>> + return &x; \ >>> +} \ >>> + \ >>> +static inline typeof(type) *tls_alloc_##x(void) \ >>> +{ \ >>> + return &x; \ >>> +} \ >>> + \ >>> +extern int dummy_##__LINE__ >> >> What's this for? >=20 > It lets you use it as >=20 > DECLARE_TLS(type, x); >=20 > Many editors impose an indent without the trailing semicolon (they pars= e > it as a K&R function definition). This workaround causes troubles here with gcc-4.5.1: In file included from /data/qemu/include/exec/memory.h:29:0, from /data/qemu/include/exec/ioport.h:29, from /data/qemu/include/hw/hw.h:11, from /data/qemu/exec.c:30: /data/qemu/include/qemu/rcu.h:88:339: warning: redundant redeclaration of= =E2=80=98dummy___LINE__=E2=80=99 /data/qemu/include/exec/cpu-all.h:362:359: note: previous declaration of = =E2=80=98dummy___LINE__=E2=80=99 was here /data/qemu/exec.c:77:24: warning: function declaration isn=E2=80=99t a pr= ototype /data/qemu/exec.c:77:41: error: invalid storage class for function =E2=80= =98tls_get_cpu_single_env=E2=80=99 /data/qemu/exec.c:77:41: error: conflicting types for =E2=80=98tls_get_cp= u_single_env=E2=80=99 /data/qemu/include/exec/cpu-all.h:362:148: note: previous definition of =E2= =80=98tls_get_cpu_single_env=E2=80=99 was here Jan --=20 Siemens AG, Corporate Technology, CT RTC ITP SES-DE Corporate Competence Center Embedded Linux