From 6d3ea6831d6fe30683d6b5078ad826fdedc2e946 Mon Sep 17 00:00:00 2001 From: Asiri Rathnayake Date: Thu, 13 Oct 2016 15:05:19 +0000 Subject: [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 --- libcxxabi/src/fallback_malloc.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'libcxxabi/src/fallback_malloc.cpp') diff --git a/libcxxabi/src/fallback_malloc.cpp b/libcxxabi/src/fallback_malloc.cpp index a436ed0ece7..5f52ece56f4 100644 --- a/libcxxabi/src/fallback_malloc.cpp +++ b/libcxxabi/src/fallback_malloc.cpp @@ -10,14 +10,11 @@ #include "fallback_malloc.h" #include "config.h" +#include "threading_support.h" #include // for malloc, calloc, free #include // for memset -#ifndef _LIBCXXABI_HAS_NO_THREADS -#include // for mutexes -#endif - // A small, simple heap manager based (loosely) on // the startup heap manager from FreeBSD, optimized for space. // @@ -32,7 +29,7 @@ namespace { // 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 @@ static void * heap_mutex = 0; 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 @@ private: mutexor ( const mutexor &rhs ); mutexor & operator = ( const mutexor &rhs ); #ifndef _LIBCXXABI_HAS_NO_THREADS - pthread_mutex_t *mtx_; + __libcxxabi_mutex_t *mtx_; #endif }; -- cgit v1.2.3