Refactor pthread usage of libcxx.

This patch extracts out all the pthread dependencies of libcxx into the
new header __threading_support. The motivation is to make it easy to
re-target libcxx into platforms that do not support pthread.

Original patch from Fulvio Esposito (fulvio.esposito@outlook.com) - D11781

Applied with tweaks - D19412

Change-Id: I301111f0075de93dd8129416e06babc195aa936b
llvm-svn: 268734
Cr-Mirrored-From: sso://chromium.googlesource.com/_direct/external/github.com/llvm/llvm-project
Cr-Mirrored-Commit: c7e4239fabf2c876449697caf05a342b01bf0312
diff --git a/src/thread.cpp b/src/thread.cpp
index 2243a34..406e71d 100644
--- a/src/thread.cpp
+++ b/src/thread.cpp
@@ -46,7 +46,7 @@
 void
 thread::join()
 {
-    int ec = pthread_join(__t_, 0);
+    int ec = __libcpp_thread_join(&__t_);
 #ifndef _LIBCPP_NO_EXCEPTIONS
     if (ec)
         throw system_error(error_code(ec, system_category()), "thread::join failed");
@@ -62,7 +62,7 @@
     int ec = EINVAL;
     if (__t_ != 0)
     {
-        ec = pthread_detach(__t_);
+        ec = __libcpp_thread_detach(&__t_);
         if (ec == 0)
             __t_ = 0;
     }