make threadlocal use conditional on configure check. NB: This revision mixes GPLv2-only and GPLv3+ code so should be considered proof of concept.

This commit is contained in:
Jan Kanis 2013-01-23 01:03:12 +01:00
parent 70a75dc88a
commit d12b1650aa
2 changed files with 41 additions and 1 deletions

View file

@ -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 <stdlib.h>
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

View file

@ -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())