From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46685) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Utb8L-0003uj-O5 for qemu-devel@nongnu.org; Mon, 01 Jul 2013 06:14:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Utb8J-0007TO-Ei for qemu-devel@nongnu.org; Mon, 01 Jul 2013 06:14:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51259) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Utb8J-0007TE-6L for qemu-devel@nongnu.org; Mon, 01 Jul 2013 06:14:55 -0400 Message-ID: <51D15699.6060708@redhat.com> Date: Mon, 01 Jul 2013 12:14:49 +0200 From: Paolo Bonzini MIME-Version: 1.0 References: <1372671341-19855-1-git-send-email-stefanha@redhat.com> <1372671341-19855-3-git-send-email-stefanha@redhat.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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: Anthony Liguori , Ed Maste , qemu-devel@nongnu.org, Stefan Hajnoczi 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/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