mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-27 20:25:12 +00:00
replace compiler-supported TLS with pthread_get/setspecific; remove GPLv3 code from two commits ago
This commit is contained in:
parent
1e65e7c996
commit
e7b3f5745c
2 changed files with 12 additions and 44 deletions
32
configure.ac
32
configure.ac
|
@ -40,38 +40,6 @@ AC_SUBST(XSEL_BIN)
|
||||||
AC_SUBST(XSEL_MAN_PATH)
|
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
|
# If needed, run autoconf to regenerate the configure file
|
||||||
|
|
24
reader.cpp
24
reader.cpp
|
@ -45,6 +45,7 @@ commence.
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <wctype.h>
|
#include <wctype.h>
|
||||||
#include <stack>
|
#include <stack>
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
#if HAVE_NCURSES_H
|
#if HAVE_NCURSES_H
|
||||||
#include <ncurses.h>
|
#include <ncurses.h>
|
||||||
|
@ -183,10 +184,8 @@ commence.
|
||||||
/* Any time the contents of a buffer changes, we update the generation count. This allows for our background highlighting thread to notice it and skip doing work that it would otherwise have to do. */
|
/* Any time the contents of a buffer changes, we update the generation count. This allows for our background highlighting thread to notice it and skip doing work that it would otherwise have to do. */
|
||||||
static volatile unsigned int s_generation_count;
|
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. */
|
/* This pthreads 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. */
|
||||||
#ifdef TLS
|
static pthread_key_t generation_count_key;
|
||||||
static TLS unsigned int thread_generation_count;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* A color is an int */
|
/* A color is an int */
|
||||||
typedef int color_t;
|
typedef int color_t;
|
||||||
|
@ -674,12 +673,8 @@ int reader_reading_interrupted()
|
||||||
|
|
||||||
bool reader_cancel_thread()
|
bool reader_cancel_thread()
|
||||||
{
|
{
|
||||||
#ifdef TLS
|
|
||||||
ASSERT_IS_BACKGROUND_THREAD();
|
ASSERT_IS_BACKGROUND_THREAD();
|
||||||
return s_generation_count != thread_generation_count;
|
return ((size_t) s_generation_count) != (size_t) pthread_getspecific(generation_count_key);
|
||||||
#else
|
|
||||||
return 0;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void reader_write_title()
|
void reader_write_title()
|
||||||
|
@ -800,6 +795,10 @@ static void exec_prompt()
|
||||||
|
|
||||||
void reader_init()
|
void reader_init()
|
||||||
{
|
{
|
||||||
|
// We store unsigned ints cast to size_t's cast to void* in pthreads tls storage
|
||||||
|
assert(sizeof(size_t) >= sizeof(unsigned int));
|
||||||
|
assert(sizeof(void*) >= sizeof(size_t));
|
||||||
|
VOMIT_ON_FAILURE(pthread_key_create(&generation_count_key, NULL));
|
||||||
|
|
||||||
tcgetattr(0,&shell_modes); /* get the current terminal modes */
|
tcgetattr(0,&shell_modes); /* get the current terminal modes */
|
||||||
memcpy(&saved_modes,
|
memcpy(&saved_modes,
|
||||||
|
@ -826,6 +825,7 @@ void reader_init()
|
||||||
void reader_destroy()
|
void reader_destroy()
|
||||||
{
|
{
|
||||||
tcsetattr(0, TCSANOW, &saved_modes);
|
tcsetattr(0, TCSANOW, &saved_modes);
|
||||||
|
pthread_key_delete(generation_count_key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1240,9 +1240,9 @@ struct autosuggestion_context_t
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef TLS
|
// The manpage doesn't list any errors pthread_setspecific can return,
|
||||||
thread_generation_count = generation_count;
|
// so I'm assuming it can not fail.
|
||||||
#endif
|
pthread_setspecific(generation_count_key, (void*)(size_t) generation_count);
|
||||||
|
|
||||||
/* Let's make sure we aren't using the empty string */
|
/* Let's make sure we aren't using the empty string */
|
||||||
if (search_string.empty())
|
if (search_string.empty())
|
||||||
|
|
Loading…
Reference in a new issue