Il 01/07/2013 11:54, Peter Maydell ha scritto:
> On 1 July 2013 10:35, Stefan Hajnoczi <stefa...@redhat.com> wrote:
>> From: Paolo Bonzini <pbonz...@redhat.com>
>>
>> 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.)
> 
>> +#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 lets you use it as

DECLARE_TLS(type, x);

Many editors impose an indent without the trailing semicolon (they parse
it as a K&R function definition).

Paolo


Reply via email to