From d12b1650aa0e58f79e3b2c05c16b58025e3ec0ea Mon Sep 17 00:00:00 2001 From: Jan Kanis Date: Wed, 23 Jan 2013 01:03:12 +0100 Subject: [PATCH] make threadlocal use conditional on configure check. NB: This revision mixes GPLv2-only and GPLv3+ code so should be considered proof of concept. --- configure.ac | 32 ++++++++++++++++++++++++++++++++ reader.cpp | 10 +++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index bf3defcff..0b4ba0dea 100644 --- a/configure.ac +++ b/configure.ac @@ -40,6 +40,38 @@ AC_SUBST(XSEL_BIN) AC_SUBST(XSEL_MAN_PATH) +# Copied from http://git.savannah.gnu.org/gitweb/?p=autoconf-archive.git;a=blob_plain;f=m4/ax_tls.m4, +# This definition is licenced under GPLv3+. +AC_DEFUN([AX_TLS], [ + AC_MSG_CHECKING(for thread local storage (TLS) class) + AC_CACHE_VAL(ac_cv_tls, [ + ax_tls_keywords="__thread __declspec(thread) none" + for ax_tls_keyword in $ax_tls_keywords; do + AS_CASE([$ax_tls_keyword], + [none], [ac_cv_tls=none ; break], + [AC_TRY_COMPILE( + [#include + static void + foo(void) { + static ] $ax_tls_keyword [ int bar; + exit(1); + }], + [], + [ac_cv_tls=$ax_tls_keyword ; break], + ac_cv_tls=none + )]) + done + ]) + AC_MSG_RESULT($ac_cv_tls) + + AS_IF([test "$ac_cv_tls" != "none"], + AC_DEFINE_UNQUOTED([TLS], $ac_cv_tls, [If the compiler supports a TLS storage class define it to that here]) + m4_ifnblank([$1], [$1]), + m4_ifnblank([$2], [$2]) + ) +]) + +AX_TLS # # If needed, run autoconf to regenerate the configure file diff --git a/reader.cpp b/reader.cpp index 8fe3a66d9..6caca362b 100644 --- a/reader.cpp +++ b/reader.cpp @@ -184,7 +184,9 @@ commence. static volatile unsigned int s_generation_count; /* This threadlocal generation count is set when an autosuggestion background thread starts up, so it can easily check if the work it is doing is no longer useful. */ -static __thread unsigned int thread_generation_count; +#ifdef TLS +static TLS unsigned int thread_generation_count; +#endif /* A color is an int */ typedef int color_t; @@ -672,8 +674,12 @@ int reader_reading_interrupted() bool reader_cancel_thread() { +#ifdef TLS ASSERT_IS_BACKGROUND_THREAD(); return s_generation_count != thread_generation_count; +#else + return 0; +#endif } void reader_write_title() @@ -1234,7 +1240,9 @@ struct autosuggestion_context_t return 0; } +#ifdef TLS thread_generation_count = generation_count; +#endif /* Let's make sure we aren't using the empty string */ if (search_string.empty())