[libcxxabi] Refactor pthread usage into a separate API

This patch refactors all pthread uses of libc++abi into a separate API. This
is the first step towards supporting an externlly-threaded libc++abi library.

I've followed the conventions already used in the libc++ library for the same
purpose.

Patch from: Saleem Abdulrasool and Asiri Rathnayake

Reviewed by: compnerd, EricWF

Differential revisions:
  https://reviews.llvm.org/D18482 (original)
  https://reviews.llvm.org/D24864 (final)

llvm-svn: 284128
Cr-Mirrored-From: sso://chromium.googlesource.com/_direct/external/github.com/llvm/llvm-project
Cr-Mirrored-Commit: 6d3ea6831d6fe30683d6b5078ad826fdedc2e946
diff --git a/src/fallback_malloc.cpp b/src/fallback_malloc.cpp
index a436ed0..5f52ece 100644
--- a/src/fallback_malloc.cpp
+++ b/src/fallback_malloc.cpp
@@ -10,14 +10,11 @@
 #include "fallback_malloc.h"
 
 #include "config.h"
+#include "threading_support.h"
 
 #include <cstdlib> // for malloc, calloc, free
 #include <cstring> // for memset
 
-#ifndef _LIBCXXABI_HAS_NO_THREADS
-#include <pthread.h> // for mutexes
-#endif
-
 //  A small, simple heap manager based (loosely) on
 //  the startup heap manager from FreeBSD, optimized for space.
 //
@@ -32,7 +29,7 @@
 
 // When POSIX threads are not available, make the mutex operations a nop
 #ifndef _LIBCXXABI_HAS_NO_THREADS
-static pthread_mutex_t heap_mutex = PTHREAD_MUTEX_INITIALIZER;
+static __libcxxabi_mutex_t heap_mutex = _LIBCXXABI_MUTEX_INITIALIZER;
 #else
 static void * heap_mutex = 0;
 #endif
@@ -40,8 +37,8 @@
 class mutexor {
 public:
 #ifndef _LIBCXXABI_HAS_NO_THREADS
-    mutexor ( pthread_mutex_t *m ) : mtx_(m) { pthread_mutex_lock ( mtx_ ); }
-    ~mutexor () { pthread_mutex_unlock ( mtx_ ); }
+    mutexor ( __libcxxabi_mutex_t *m ) : mtx_(m) { __libcxxabi_mutex_lock ( mtx_ ); }
+    ~mutexor () { __libcxxabi_mutex_unlock ( mtx_ ); }
 #else
     mutexor ( void * ) {}
     ~mutexor () {}
@@ -50,7 +47,7 @@
     mutexor ( const mutexor &rhs );
     mutexor & operator = ( const mutexor &rhs );
 #ifndef _LIBCXXABI_HAS_NO_THREADS
-    pthread_mutex_t *mtx_;
+    __libcxxabi_mutex_t *mtx_;
 #endif
     };