[libcxx] Allow explicit pthread opt-in

The existing pthread detection code in __config is pretty good for
common operating systems. It doesn't allow cmake-time choices to be
made for uncommon operating systems though.

This change adds the LIBCXX_HAS_PTHREAD_API cmake flag, which turns
into the _LIBCPP_HAS_THREAD_API_PTHREAD preprocessor define. This is
a name change from the old _LIBCPP_THREAD_API_PTHREAD. The lit tests
want __config_site.in variables to have a _LIBCPP_HAS prefix.

http://reviews.llvm.org/D20573


git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@270735 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Ben Craig
2016-05-25 17:40:09 +00:00
parent fc1962da37
commit 5163e46afb
4 changed files with 18 additions and 6 deletions

View File

@@ -126,6 +126,7 @@ option(LIBCXX_ENABLE_MONOTONIC_CLOCK
"Build libc++ with support for a monotonic clock. "Build libc++ with support for a monotonic clock.
This option may only be set to OFF when LIBCXX_ENABLE_THREADS=OFF." ON) This option may only be set to OFF when LIBCXX_ENABLE_THREADS=OFF." ON)
option(LIBCXX_HAS_MUSL_LIBC "Build libc++ with support for the Musl C library" OFF) option(LIBCXX_HAS_MUSL_LIBC "Build libc++ with support for the Musl C library" OFF)
option(LIBCXX_HAS_PTHREAD_API "Ignore auto-detection and force use of pthread API" OFF)
# Misc options ---------------------------------------------------------------- # Misc options ----------------------------------------------------------------
# FIXME: Turn -pedantic back ON. It is currently off because it warns # FIXME: Turn -pedantic back ON. It is currently off because it warns
@@ -172,6 +173,11 @@ if(LIBCXX_ENABLE_THREADS AND NOT LIBCXX_ENABLE_MONOTONIC_CLOCK)
" when LIBCXX_ENABLE_THREADS is also set to OFF.") " when LIBCXX_ENABLE_THREADS is also set to OFF.")
endif() endif()
if(LIBCXX_HAS_PTHREAD_API AND NOT LIBCXX_ENABLE_THREADS)
message(FATAL_ERROR "LIBCXX_HAS_PTHREAD_API can only be set to ON"
" when LIBCXX_ENABLE_THREADS is also set to ON.")
endif()
# Ensure LLVM_USE_SANITIZER is not specified when LIBCXX_GENERATE_COVERAGE # Ensure LLVM_USE_SANITIZER is not specified when LIBCXX_GENERATE_COVERAGE
# is ON. # is ON.
if (LLVM_USE_SANITIZER AND LIBCXX_GENERATE_COVERAGE) if (LLVM_USE_SANITIZER AND LIBCXX_GENERATE_COVERAGE)
@@ -384,6 +390,7 @@ config_define_if_not(LIBCXX_ENABLE_THREADS _LIBCPP_HAS_NO_THREADS)
config_define_if_not(LIBCXX_ENABLE_MONOTONIC_CLOCK _LIBCPP_HAS_NO_MONOTONIC_CLOCK) config_define_if_not(LIBCXX_ENABLE_MONOTONIC_CLOCK _LIBCPP_HAS_NO_MONOTONIC_CLOCK)
config_define_if_not(LIBCXX_ENABLE_THREAD_UNSAFE_C_FUNCTIONS _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS) config_define_if_not(LIBCXX_ENABLE_THREAD_UNSAFE_C_FUNCTIONS _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS)
config_define_if(LIBCXX_HAS_PTHREAD_API _LIBCPP_HAS_THREAD_API_PTHREAD)
config_define_if(LIBCXX_HAS_MUSL_LIBC _LIBCPP_HAS_MUSL_LIBC) config_define_if(LIBCXX_HAS_MUSL_LIBC _LIBCPP_HAS_MUSL_LIBC)
if (LIBCXX_NEEDS_SITE_CONFIG) if (LIBCXX_NEEDS_SITE_CONFIG)

View File

@@ -813,19 +813,23 @@ extern "C" void __sanitizer_annotate_contiguous_container(
#endif #endif
// Thread API // Thread API
#ifndef _LIBCPP_HAS_NO_THREADS #if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
# if defined(__FreeBSD__) || \ # if defined(__FreeBSD__) || \
defined(__NetBSD__) || \ defined(__NetBSD__) || \
defined(__linux__) || \ defined(__linux__) || \
defined(__APPLE__) || \ defined(__APPLE__) || \
defined(__CloudABI__) || \ defined(__CloudABI__) || \
defined(__sun__) defined(__sun__)
# define _LIBCPP_THREAD_API_PTHREAD # define _LIBCPP_HAS_THREAD_API_PTHREAD
# else # else
# error "No thread API" # error "No thread API"
# endif // _LIBCPP_THREAD_API # endif // _LIBCPP_HAS_THREAD_API
#endif // _LIBCPP_HAS_NO_THREADS #endif // _LIBCPP_HAS_NO_THREADS
#if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
# error _LIBCPP_HAS_THREAD_API_PTHREAD may only be defined when \
_LIBCPP_HAS_NO_THREADS is not defined.
#endif
#if defined(_LIBCPP_HAS_NO_MONOTONIC_CLOCK) && !defined(_LIBCPP_HAS_NO_THREADS) #if defined(_LIBCPP_HAS_NO_MONOTONIC_CLOCK) && !defined(_LIBCPP_HAS_NO_THREADS)
# error _LIBCPP_HAS_NO_MONOTONIC_CLOCK may only be defined when \ # error _LIBCPP_HAS_NO_MONOTONIC_CLOCK may only be defined when \

View File

@@ -19,5 +19,6 @@
#cmakedefine _LIBCPP_HAS_NO_MONOTONIC_CLOCK #cmakedefine _LIBCPP_HAS_NO_MONOTONIC_CLOCK
#cmakedefine _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS #cmakedefine _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS
#cmakedefine _LIBCPP_HAS_MUSL_LIBC #cmakedefine _LIBCPP_HAS_MUSL_LIBC
#cmakedefine _LIBCPP_HAS_THREAD_API_PTHREAD
#endif // _LIBCPP_CONFIG_SITE #endif // _LIBCPP_CONFIG_SITE

View File

@@ -19,14 +19,14 @@
#ifndef _LIBCPP_HAS_NO_THREADS #ifndef _LIBCPP_HAS_NO_THREADS
#if defined(_LIBCPP_THREAD_API_PTHREAD) #if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
#include <pthread.h> #include <pthread.h>
#include <sched.h> #include <sched.h>
#endif #endif
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD
#if defined(_LIBCPP_THREAD_API_PTHREAD) #if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
// Mutex // Mutex
#define _LIBCPP_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER #define _LIBCPP_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
@@ -194,7 +194,7 @@ void __libcpp_tl_set(__libcpp_tl_key __key, void* __p)
pthread_setspecific(__key, __p); pthread_setspecific(__key, __p);
} }
#else // !_LIBCPP_THREAD_API_PTHREAD #else // !_LIBCPP_HAS_THREAD_API_PTHREAD
#error "No thread API selected." #error "No thread API selected."
#endif #endif