[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.

llvm-svn: 290878
diff --git a/libcxx/include/__threading_support b/libcxx/include/__threading_support
index f4d41f7..0064c7d 100644
--- a/libcxx/include/__threading_support
+++ b/libcxx/include/__threading_support
@@ -28,11 +28,23 @@
 #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 <pthread.h>
 #include <sched.h>
 #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 @@
 _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)
 {