From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37747) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UtdJy-0006Zx-N4 for qemu-devel@nongnu.org; Mon, 01 Jul 2013 08:35:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UtdJq-0006LK-4B for qemu-devel@nongnu.org; Mon, 01 Jul 2013 08:35:06 -0400 Received: from mx1.redhat.com ([209.132.183.28]:19220) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UtdJp-0006Kz-S0 for qemu-devel@nongnu.org; Mon, 01 Jul 2013 08:34:58 -0400 Date: Mon, 1 Jul 2013 14:34:53 +0200 From: Stefan Hajnoczi Message-ID: <20130701123453.GA19303@stefanha-thinkpad.redhat.com> References: <1372671341-19855-1-git-send-email-stefanha@redhat.com> <1372671341-19855-3-git-send-email-stefanha@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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: Peter Maydell Cc: Paolo Bonzini , Anthony Liguori , Ed Maste , qemu-devel@nongnu.org On Mon, Jul 01, 2013 at 10:54:56AM +0100, Peter Maydell wrote: > 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/setspecific > > on POSIX systems that lack __thread, but uses the dynamic linker's TLS > > support on Linux and Windows. > > > > The user shall call tls_alloc_foo() in every thread that needs to access > > the variable---exactly once and before any access. foo is the name of > > the variable as passed to DECLARE_TLS and DEFINE_TLS. Then, > > tls_get_foo() will return the address of the variable. It is guaranteed > > 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" = 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.) You are right, gcc emits a warning. > > +#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? It makes the DECLARE_TLS() macro use a semicolon.