From patchwork Tue Dec 1 12:51:36 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [v2,10/11] Use __thread where available. Date: Tue, 01 Dec 2009 02:51:36 -0000 From: Glauber Costa X-Patchwork-Id: 39908 Message-Id: <1259671897-22232-11-git-send-email-glommer@redhat.com> To: qemu-devel@nongnu.org Cc: aliguori@us.ibm.com, avi@redhat.com, agraf@suse.de It is much faster than pthread_{g,s}et_specific. Signed-off-by: Glauber Costa --- configure | 17 +++++++++++++++++ vl.c | 16 ++++++++++++++++ 2 files changed, 33 insertions(+), 0 deletions(-) diff --git a/configure b/configure index dca5a43..ce7bcc4 100755 --- a/configure +++ b/configure @@ -233,6 +233,7 @@ blobs="yes" pkgversion="" check_utests="no" user_pie="no" +tls_thread="yes" # OS specific if check_define __linux__ ; then @@ -1017,6 +1018,19 @@ EOF fi ########################################## +# Check for availability of the __thread keyword +cat > $TMPC < $TMPC <> $config_host_mak if test "$mixemu" = "yes" ; then echo "CONFIG_MIXEMU=y" >> $config_host_mak fi +if test "$tls_thread" = "yes" ; then + echo "CONFIG_TLS_HAS_THREAD=y" >> $config_host_mak +fi if test "$vnc_tls" = "yes" ; then echo "CONFIG_VNC_TLS=y" >> $config_host_mak echo "VNC_TLS_CFLAGS=$vnc_tls_cflags" >> $config_host_mak diff --git a/vl.c b/vl.c index ad2e7d6..16a41e3 100644 --- a/vl.c +++ b/vl.c @@ -3445,21 +3445,37 @@ static void block_io_signals(void); static void unblock_io_signals(void); static int tcg_has_work(void); +#ifdef CONFIG_TLS_HAS_THREAD +static __thread CPUState *current_env; +#else static pthread_key_t current_env; +#endif static CPUState *qemu_get_current_env(void) { +#ifdef CONFIG_TLS_HAS_THREAD + return current_env; +#else return pthread_getspecific(current_env); +#endif } static void qemu_set_current_env(CPUState *env) { +#ifdef CONFIG_TLS_HAS_THREAD + current_env = env; +#else pthread_setspecific(current_env, env); +#endif } static void qemu_init_current_env(void) { +#ifdef CONFIG_TLS_HAS_THREAD + current_env = NULL; +#else pthread_key_create(¤t_env, NULL); +#endif } static int qemu_init_main_loop(void)