qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 2/2] qemu-thread: add TLS wrappers


From: Stefan Hajnoczi
Subject: Re: [Qemu-devel] [PATCH 2/2] qemu-thread: add TLS wrappers
Date: Mon, 1 Jul 2013 14:34:53 +0200
User-agent: Mutt/1.5.21 (2010-09-15)

On Mon, Jul 01, 2013 at 10:54:56AM +0100, Peter Maydell wrote:
> On 1 July 2013 10:35, Stefan Hajnoczi <address@hidden> wrote:
> > From: Paolo Bonzini <address@hidden>
> >
> > 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.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]