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: Jan Kiszka
Subject: Re: [Qemu-devel] [PATCH 2/2] qemu-thread: add TLS wrappers
Date: Thu, 04 Jul 2013 18:27:13 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686 (x86_64); de; rv:1.8.1.12) Gecko/20080226 SUSE/2.0.0.12-1.1 Thunderbird/2.0.0.12 Mnenhy/0.7.5.666

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 <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.)
>>
>>> +#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).

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 
‘dummy___LINE__’
/data/qemu/include/exec/cpu-all.h:362:359: note: previous declaration of 
‘dummy___LINE__’ was here
/data/qemu/exec.c:77:24: warning: function declaration isn’t a prototype
/data/qemu/exec.c:77:41: error: invalid storage class for function 
‘tls_get_cpu_single_env’
/data/qemu/exec.c:77:41: error: conflicting types for ‘tls_get_cpu_single_env’
/data/qemu/include/exec/cpu-all.h:362:148: note: previous definition of 
‘tls_get_cpu_single_env’ was here

Jan

-- 
Siemens AG, Corporate Technology, CT RTC ITP SES-DE
Corporate Competence Center Embedded Linux



reply via email to

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