mirror of
https://github.com/fish-shell/fish-shell
synced 2024-11-10 23:24:39 +00:00
Guard thread_local
Mac OS X 10.9 supports __thread but not C++11 thread_local. Teach CMake to detect support for thread_local and use the proper define guard. Fixes #7023
This commit is contained in:
parent
1fd0cd5510
commit
84e0c8d32e
4 changed files with 26 additions and 1 deletions
|
@ -186,6 +186,16 @@ int main () {
|
|||
HAVE_STD__MAKE_UNIQUE
|
||||
)
|
||||
|
||||
# Detect support for thread_local.
|
||||
check_cxx_source_compiles("
|
||||
int main () {
|
||||
static thread_local int x = 3;
|
||||
(void)x;
|
||||
}
|
||||
"
|
||||
HAVE_CX11_THREAD_LOCAL
|
||||
)
|
||||
|
||||
find_program(SED sed)
|
||||
|
||||
check_cxx_source_compiles("
|
||||
|
|
|
@ -10,6 +10,9 @@
|
|||
/* Define to 1 if you have the `ctermid_r' function. */
|
||||
#cmakedefine HAVE_CTERMID_R 1
|
||||
|
||||
/* Define to 1 if C++11 thread_local is supported. */
|
||||
#cmakedefine HAVE_CX11_THREAD_LOCAL 1
|
||||
|
||||
/* Define to 1 if you have the `dirfd' function. */
|
||||
#cmakedefine HAVE_DIRFD 1
|
||||
|
||||
|
|
|
@ -34,6 +34,18 @@ int fish_wcswidth(const wchar_t *str, size_t n);
|
|||
// otherwise it uses mkstemp followed by fcntl
|
||||
int fish_mkstemp_cloexec(char *);
|
||||
|
||||
/// thread_local support.
|
||||
#if HAVE_CX11_THREAD_LOCAL
|
||||
# define FISH_THREAD_LOCAL thread_local
|
||||
#elif defined (__GNUC__)
|
||||
# define FISH_THREAD_LOCAL __thread
|
||||
#elif defined (_MSC_VER)
|
||||
# define FISH_THREAD_LOCAL __declspec(thread)
|
||||
#else // !C++11 && !__GNUC__ && !_MSC_VER
|
||||
# error "No known thread local storage qualifier for this platform"
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef WCHAR_MAX
|
||||
/// This _should_ be defined by wchar.h, but e.g. OpenBSD doesn't.
|
||||
#define WCHAR_MAX INT_MAX
|
||||
|
|
|
@ -491,7 +491,7 @@ static uint64_t next_thread_id() {
|
|||
}
|
||||
|
||||
uint64_t thread_id() {
|
||||
static thread_local uint64_t tl_tid = next_thread_id();
|
||||
static FISH_THREAD_LOCAL uint64_t tl_tid = next_thread_id();
|
||||
return tl_tid;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue