From e29d9ff93626b580868f826a5ece1deab7e4b03a Mon Sep 17 00:00:00 2001 From: Asiri Rathnayake Date: Tue, 3 Jan 2017 11:32:31 +0000 Subject: [PATCH] [libcxx] Fix testing of the externally-threaded library build after r290850 Before r290850, building libcxx with -DLIBCXX_HAS_EXTERNAL_THREAD_API=ON had two uses: - Allow platform vendors to plug-in an __external_threading header which should take care of the entire threading infrastructure of libcxx - Allow testing of an externally-threaded library build; where the thread API is declared using pthread data structures, and the implementation of this API is provided as a separate library (test/support/external_threads.cpp) and linked-in when running the test suite. r290850 breaks the second use case (pthread data structures are no longer available). This patch re-stores the ability to build+test an externally-threaded library variant on a pthread based system. git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@290878 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/__threading_support | 20 +++++++++++++++++--- test/support/external_threads.cpp | 2 +- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/include/__threading_support b/include/__threading_support index f4d41f7a1..0064c7d59 100644 --- a/include/__threading_support +++ b/include/__threading_support @@ -27,12 +27,24 @@ #endif #endif +#if defined(_LIBCPP_HAS_THREAD_API_EXTERNAL) && \ + !__libcpp_has_include(<__external_threading>) +// If the <__external_threading> header is absent, build libc++ against a +// pthread-oriented thread api but leave out its implementation. This setup +// allows building+testing of an externally-threaded library variant (on any +// platform that supports pthreads). Here, an 'externally-threaded' library +// variant is one where the implementation of the libc++ thread api is provided +// as a separate library. +#define _LIBCPP_HAS_THREAD_API_EXTERNAL_PTHREAD +#endif + #if defined(_LIBCPP_HAS_THREAD_API_EXTERNAL) && \ __libcpp_has_include(<__external_threading>) #include <__external_threading> #else -#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD) +#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD) || \ + defined(_LIBCPP_HAS_THREAD_API_EXTERNAL_PTHREAD) #include #include #endif @@ -45,7 +57,8 @@ _LIBCPP_BEGIN_NAMESPACE_STD -#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD) +#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD) || \ + defined(_LIBCPP_HAS_THREAD_API_EXTERNAL_PTHREAD) // Mutex typedef pthread_mutex_t __libcpp_mutex_t; #define _LIBCPP_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER @@ -134,7 +147,8 @@ void *__libcpp_tls_get(__libcpp_tls_key __key); _LIBCPP_THREAD_ABI_VISIBILITY void __libcpp_tls_set(__libcpp_tls_key __key, void *__p); -#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD) +#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD) || \ + defined(_LIBCPP_BUILDING_THREAD_API_EXTERNAL_PTHREAD) int __libcpp_recursive_mutex_init(__libcpp_mutex_t *__m) { diff --git a/test/support/external_threads.cpp b/test/support/external_threads.cpp index 5f7106b22..68ba96ff8 100644 --- a/test/support/external_threads.cpp +++ b/test/support/external_threads.cpp @@ -6,5 +6,5 @@ // Source Licenses. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#define _LIBCPP_HAS_THREAD_API_PTHREAD +#define _LIBCPP_BUILDING_THREAD_API_EXTERNAL_PTHREAD #include <__threading_support>