<div dir="ltr">Looks like this broke the gcc builder: <a href="http://lab.llvm.org:8011/builders/libcxx-libcxxabi-x86_64-linux-ubuntu-gcc49-cxx11/builds/573/steps/build.libcxxabi/logs/stdio">http://lab.llvm.org:8011/builders/libcxx-libcxxabi-x86_64-linux-ubuntu-gcc49-cxx11/builds/573/steps/build.libcxxabi/logs/stdio</a><div><br></div><div>I'll have a look soon, might not be able to do so before tomorrow. Please feel free to revert if this is blocking.</div><div><br></div><div>Sorry for the trouble.</div><div><br></div><div>/ Asiri</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Oct 13, 2016 at 4:05 PM, Asiri Rathnayake via cfe-commits <span dir="ltr"><<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: asiri<br>
Date: Thu Oct 13 10:05:19 2016<br>
New Revision: 284128<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=284128&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=284128&view=rev</a><br>
Log:<br>
[libcxxabi] Refactor pthread usage into a separate API<br>
<br>
This patch refactors all pthread uses of libc++abi into a separate API. This<br>
is the first step towards supporting an externlly-threaded libc++abi library.<br>
<br>
I've followed the conventions already used in the libc++ library for the same<br>
purpose.<br>
<br>
Patch from: Saleem Abdulrasool and Asiri Rathnayake<br>
<br>
Reviewed by: compnerd, EricWF<br>
<br>
Differential revisions:<br>
<a href="https://reviews.llvm.org/D18482" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D18482</a> (original)<br>
<a href="https://reviews.llvm.org/D24864" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D24864</a> (final)<br>
<br>
Added:<br>
libcxxabi/trunk/src/threading_<wbr>support.h<br>
Modified:<br>
libcxxabi/trunk/CMakeLists.txt<br>
libcxxabi/trunk/src/config.h<br>
libcxxabi/trunk/src/cxa_<wbr>exception.cpp<br>
libcxxabi/trunk/src/cxa_<wbr>exception_storage.cpp<br>
libcxxabi/trunk/src/cxa_guard.<wbr>cpp<br>
libcxxabi/trunk/src/cxa_<wbr>thread_atexit.cpp<br>
libcxxabi/trunk/src/fallback_<wbr>malloc.cpp<br>
libcxxabi/trunk/test/test_<wbr>exception_storage.pass.cpp<br>
libcxxabi/trunk/test/test_<wbr>fallback_malloc.pass.cpp<br>
<br>
Modified: libcxxabi/trunk/CMakeLists.txt<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/CMakeLists.txt?rev=284128&r1=284127&r2=284128&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/libcxxabi/trunk/<wbr>CMakeLists.txt?rev=284128&r1=<wbr>284127&r2=284128&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- libcxxabi/trunk/CMakeLists.txt (original)<br>
+++ libcxxabi/trunk/CMakeLists.txt Thu Oct 13 10:05:19 2016<br>
@@ -340,6 +340,7 @@ endif()<br>
<br>
if (LIBCXXABI_HAS_PTHREAD_API)<br>
add_definitions(-D_LIBCPP_HAS_<wbr>THREAD_API_PTHREAD)<br>
+ add_definitions(-D_LIBCXXABI_<wbr>USE_THREAD_API_PTHREAD)<br>
endif()<br>
<br>
if (MSVC)<br>
<br>
Modified: libcxxabi/trunk/src/config.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/config.h?rev=284128&r1=284127&r2=284128&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/libcxxabi/trunk/src/<wbr>config.h?rev=284128&r1=284127&<wbr>r2=284128&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- libcxxabi/trunk/src/config.h (original)<br>
+++ libcxxabi/trunk/src/config.h Thu Oct 13 10:05:19 2016<br>
@@ -16,6 +16,36 @@<br>
<br>
#include <unistd.h><br>
<br>
+// Configure inline visibility attributes<br>
+#if defined(_WIN32)<br>
+ #if defined(_MSC_VER) && !defined(__clang__)<br>
+ // Using Microsoft Visual C++ compiler<br>
+ #define _LIBCXXABI_INLINE_VISIBILITY __forceinline<br>
+ #else<br>
+ #if __has_attribute(__internal_<wbr>linkage__)<br>
+ #define _LIBCXXABI_INLINE_VISIBILITY __attribute__ ((__internal_linkage__, __always_inline__))<br>
+ #else<br>
+ #define _LIBCXXABI_INLINE_VISIBILITY __attribute__ ((__always_inline__))<br>
+ #endif<br>
+ #endif<br>
+#else<br>
+ #if __has_attribute(__internal_<wbr>linkage__)<br>
+ #define _LIBCXXABI_INLINE_VISIBILITY __attribute__ ((__internal_linkage__, __always_inline__))<br>
+ #else<br>
+ #define _LIBCXXABI_INLINE_VISIBILITY __attribute__ ((__visibility__("hidden"), __always_inline__))<br>
+ #endif<br>
+#endif<br>
+<br>
+// Try and deduce a threading api if one has not been explicitly set.<br>
+#if !defined(_LIBCXXABI_HAS_NO_<wbr>THREADS) && \<br>
+ !defined(_LIBCXXABI_USE_<wbr>THREAD_API_PTHREAD)<br>
+ #if defined(_POSIX_THREADS) && _POSIX_THREADS >= 0<br>
+ #define _LIBCXXABI_USE_THREAD_API_<wbr>PTHREAD<br>
+ #else<br>
+ #error "No thread API"<br>
+ #endif<br>
+#endif<br>
+<br>
// Set this in the CXXFLAGS when you need it, because otherwise we'd have to<br>
// #if !defined(__linux__) && !defined(__APPLE__) && ...<br>
// and so-on for *every* platform.<br>
<br>
Modified: libcxxabi/trunk/src/cxa_<wbr>exception.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/cxa_exception.cpp?rev=284128&r1=284127&r2=284128&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/libcxxabi/trunk/src/<wbr>cxa_exception.cpp?rev=284128&<wbr>r1=284127&r2=284128&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- libcxxabi/trunk/src/cxa_<wbr>exception.cpp (original)<br>
+++ libcxxabi/trunk/src/cxa_<wbr>exception.cpp Thu Oct 13 10:05:19 2016<br>
@@ -12,6 +12,7 @@<br>
//===-------------------------<wbr>------------------------------<wbr>---------------===//<br>
<br>
#include "config.h"<br>
+#include "threading_support.h"<br>
#include "cxxabi.h"<br>
<br>
#include <exception> // for std::terminate<br>
<br>
Modified: libcxxabi/trunk/src/cxa_<wbr>exception_storage.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/cxa_exception_storage.cpp?rev=284128&r1=284127&r2=284128&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/libcxxabi/trunk/src/<wbr>cxa_exception_storage.cpp?rev=<wbr>284128&r1=284127&r2=284128&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- libcxxabi/trunk/src/cxa_<wbr>exception_storage.cpp (original)<br>
+++ libcxxabi/trunk/src/cxa_<wbr>exception_storage.cpp Thu Oct 13 10:05:19 2016<br>
@@ -14,6 +14,7 @@<br>
#include "cxa_exception.hpp"<br>
<br>
#include "config.h"<br>
+#include "threading_support.h"<br>
<br>
#if defined(_LIBCXXABI_HAS_NO_<wbr>THREADS)<br>
<br>
@@ -44,28 +45,27 @@ extern "C" {<br>
<br>
#else<br>
<br>
-#include <pthread.h><br>
#include "abort_message.h"<br>
#include "fallback_malloc.h"<br>
<br>
-// In general, we treat all pthread errors as fatal.<br>
+// In general, we treat all threading errors as fatal.<br>
// We cannot call std::terminate() because that will in turn<br>
// call __cxa_get_globals() and cause infinite recursion.<br>
<br>
namespace __cxxabiv1 {<br>
namespace {<br>
- pthread_key_t key_;<br>
- pthread_once_t flag_ = PTHREAD_ONCE_INIT;<br>
+ __libcxxabi_tls_key key_;<br>
+ __libcxxabi_exec_once_flag flag_ = _LIBCXXABI_EXEC_ONCE_<wbr>INITIALIZER;<br>
<br>
void destruct_ (void *p) {<br>
__free_with_fallback ( p );<br>
- if ( 0 != ::pthread_setspecific ( key_, NULL ) )<br>
+ if ( 0 != __libcxxabi_tls_set ( key_, NULL ) )<br>
abort_message("cannot zero out thread value for __cxa_get_globals()");<br>
}<br>
<br>
void construct_ () {<br>
- if ( 0 != pthread_key_create ( &key_, destruct_ ) )<br>
- abort_message("cannot create pthread key for __cxa_get_globals()");<br>
+ if ( 0 != __libcxxabi_tls_create ( &key_, destruct_ ) )<br>
+ abort_message("cannot create thread specific key for __cxa_get_globals()");<br>
}<br>
}<br>
<br>
@@ -80,8 +80,8 @@ extern "C" {<br>
(__calloc_with_fallback (1, sizeof (__cxa_eh_globals)));<br>
if ( NULL == retVal )<br>
abort_message("cannot allocate __cxa_eh_globals");<br>
- if ( 0 != pthread_setspecific ( key_, retVal ) )<br>
- abort_message("pthread_<wbr>setspecific failure in __cxa_get_globals()");<br>
+ if ( 0 != __libcxxabi_tls_set ( key_, retVal ) )<br>
+ abort_message("__libcxxabi_<wbr>tls_set failure in __cxa_get_globals()");<br>
}<br>
return retVal;<br>
}<br>
@@ -92,10 +92,10 @@ extern "C" {<br>
// libc++abi.<br>
__cxa_eh_globals * __cxa_get_globals_fast () {<br>
// First time through, create the key.<br>
- if (0 != pthread_once(&flag_, construct_))<br>
- abort_message("pthread_once failure in __cxa_get_globals_fast()");<br>
+ if (0 != __libcxxabi_execute_once(&<wbr>flag_, construct_))<br>
+ abort_message("execute once failure in __cxa_get_globals_fast()");<br>
// static int init = construct_();<br>
- return static_cast<__cxa_eh_globals*><wbr>(::pthread_getspecific(key_));<br>
+ return static_cast<__cxa_eh_globals*><wbr>(__libcxxabi_tls_get(key_));<br>
}<br>
<br>
}<br>
<br>
Modified: libcxxabi/trunk/src/cxa_guard.<wbr>cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/cxa_guard.cpp?rev=284128&r1=284127&r2=284128&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/libcxxabi/trunk/src/<wbr>cxa_guard.cpp?rev=284128&r1=<wbr>284127&r2=284128&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- libcxxabi/trunk/src/cxa_guard.<wbr>cpp (original)<br>
+++ libcxxabi/trunk/src/cxa_guard.<wbr>cpp Thu Oct 13 10:05:19 2016<br>
@@ -11,10 +11,8 @@<br>
<br>
#include "abort_message.h"<br>
#include "config.h"<br>
+#include "threading_support.h"<br>
<br>
-#ifndef _LIBCXXABI_HAS_NO_THREADS<br>
-# include <pthread.h><br>
-#endif<br>
#include <stdint.h><br>
<br>
/*<br>
@@ -22,9 +20,9 @@<br>
which will turn around and try to call __cxa_guard_acquire reentrantly.<br>
For this reason, the headers of this file are as restricted as possible.<br>
Previous implementations of this code for __APPLE__ have used<br>
- pthread_mutex_lock and the abort_message utility without problem. This<br>
- implementation also uses pthread_cond_wait which has tested to not be a<br>
- problem.<br>
+ __libcxxabi_mutex_lock and the abort_message utility without problem. This<br>
+ implementation also uses __libcxxabi_condvar_wait which has tested<br>
+ to not be a problem.<br>
*/<br>
<br>
namespace __cxxabiv1<br>
@@ -69,8 +67,8 @@ bool is_initialized(guard_type* guard_ob<br>
#endif<br>
<br>
#ifndef _LIBCXXABI_HAS_NO_THREADS<br>
-pthread_mutex_t guard_mut = PTHREAD_MUTEX_INITIALIZER;<br>
-pthread_cond_t guard_cv = PTHREAD_COND_INITIALIZER;<br>
+__libcxxabi_mutex_t guard_mut = _LIBCXXABI_MUTEX_INITIALIZER;<br>
+__libcxxabi_condvar_t guard_cv = _LIBCXXABI_CONDVAR_<wbr>INITIALIZER;<br>
#endif<br>
<br>
#if defined(__APPLE__) && !defined(__arm__)<br>
@@ -175,13 +173,13 @@ extern "C"<br>
#ifndef _LIBCXXABI_HAS_NO_THREADS<br>
_LIBCXXABI_FUNC_VIS int __cxa_guard_acquire(guard_type *guard_object) {<br>
char* initialized = (char*)guard_object;<br>
- if (pthread_mutex_lock(&guard_<wbr>mut))<br>
+ if (__libcxxabi_mutex_lock(&<wbr>guard_mut))<br>
abort_message("__cxa_guard_<wbr>acquire failed to acquire mutex");<br>
int result = *initialized == 0;<br>
if (result)<br>
{<br>
#if defined(__APPLE__) && !defined(__arm__)<br>
- const lock_type id = pthread_mach_thread_np(<wbr>pthread_self());<br>
+ const lock_type id = __libcxxabi_thread_get_port();<br>
lock_type lock = get_lock(*guard_object);<br>
if (lock)<br>
{<br>
@@ -190,7 +188,7 @@ _LIBCXXABI_FUNC_VIS int __cxa_guard_acqu<br>
abort_message("__cxa_guard_<wbr>acquire detected deadlock");<br>
do<br>
{<br>
- if (pthread_cond_wait(&guard_cv, &guard_mut))<br>
+ if (__libcxxabi_condvar_wait(&<wbr>guard_cv, &guard_mut))<br>
abort_message("__cxa_guard_<wbr>acquire condition variable wait failed");<br>
lock = get_lock(*guard_object);<br>
} while (lock);<br>
@@ -202,36 +200,36 @@ _LIBCXXABI_FUNC_VIS int __cxa_guard_acqu<br>
set_lock(*guard_object, id);<br>
#else // !__APPLE__ || __arm__<br>
while (get_lock(*guard_object))<br>
- if (pthread_cond_wait(&guard_cv, &guard_mut))<br>
+ if (__libcxxabi_condvar_wait(&<wbr>guard_cv, &guard_mut))<br>
abort_message("__cxa_guard_<wbr>acquire condition variable wait failed");<br>
result = *initialized == 0;<br>
if (result)<br>
set_lock(*guard_object, true);<br>
#endif // !__APPLE__ || __arm__<br>
}<br>
- if (pthread_mutex_unlock(&guard_<wbr>mut))<br>
+ if (__libcxxabi_mutex_unlock(&<wbr>guard_mut))<br>
abort_message("__cxa_guard_<wbr>acquire failed to release mutex");<br>
return result;<br>
}<br>
<br>
_LIBCXXABI_FUNC_VIS void __cxa_guard_release(guard_type *guard_object) {<br>
- if (pthread_mutex_lock(&guard_<wbr>mut))<br>
+ if (__libcxxabi_mutex_lock(&<wbr>guard_mut))<br>
abort_message("__cxa_guard_<wbr>release failed to acquire mutex");<br>
*guard_object = 0;<br>
set_initialized(guard_object);<br>
- if (pthread_mutex_unlock(&guard_<wbr>mut))<br>
+ if (__libcxxabi_mutex_unlock(&<wbr>guard_mut))<br>
abort_message("__cxa_guard_<wbr>release failed to release mutex");<br>
- if (pthread_cond_broadcast(&<wbr>guard_cv))<br>
+ if (__libcxxabi_condvar_<wbr>broadcast(&guard_cv))<br>
abort_message("__cxa_guard_<wbr>release failed to broadcast condition variable");<br>
}<br>
<br>
_LIBCXXABI_FUNC_VIS void __cxa_guard_abort(guard_type *guard_object) {<br>
- if (pthread_mutex_lock(&guard_<wbr>mut))<br>
+ if (__libcxxabi_mutex_lock(&<wbr>guard_mut))<br>
abort_message("__cxa_guard_<wbr>abort failed to acquire mutex");<br>
*guard_object = 0;<br>
- if (pthread_mutex_unlock(&guard_<wbr>mut))<br>
+ if (__libcxxabi_mutex_unlock(&<wbr>guard_mut))<br>
abort_message("__cxa_guard_<wbr>abort failed to release mutex");<br>
- if (pthread_cond_broadcast(&<wbr>guard_cv))<br>
+ if (__libcxxabi_condvar_<wbr>broadcast(&guard_cv))<br>
abort_message("__cxa_guard_<wbr>abort failed to broadcast condition variable");<br>
}<br>
<br>
<br>
Modified: libcxxabi/trunk/src/cxa_<wbr>thread_atexit.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/cxa_thread_atexit.cpp?rev=284128&r1=284127&r2=284128&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/libcxxabi/trunk/src/<wbr>cxa_thread_atexit.cpp?rev=<wbr>284128&r1=284127&r2=284128&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- libcxxabi/trunk/src/cxa_<wbr>thread_atexit.cpp (original)<br>
+++ libcxxabi/trunk/src/cxa_<wbr>thread_atexit.cpp Thu Oct 13 10:05:19 2016<br>
@@ -9,8 +9,8 @@<br>
<br>
#include "abort_message.h"<br>
#include "cxxabi.h"<br>
+#include "threading_support.h"<br>
#include <cstdlib><br>
-#include <pthread.h><br>
<br>
namespace __cxxabiv1 {<br>
<br>
@@ -39,9 +39,10 @@ namespace {<br>
// destructors of any objects with static storage duration.<br>
//<br>
// - thread_local destructors on non-main threads run on the first iteration<br>
- // through the pthread_key destructors. std::notify_all_at_thread_<wbr>exit()<br>
- // and similar functions must be careful to wait until the second iteration<br>
- // to provide their intended ordering guarantees.<br>
+ // through the __libcxxabi_tls_key destructors.<br>
+ // std::notify_all_at_thread_<wbr>exit() and similar functions must be careful to<br>
+ // wait until the second iteration to provide their intended ordering<br>
+ // guarantees.<br>
//<br>
// Another limitation, though one shared with ..._impl(), is that any<br>
// thread_locals that are first initialized after non-thread_local global<br>
@@ -65,7 +66,7 @@ namespace {<br>
// True if the destructors are currently scheduled to run on this thread<br>
__thread bool dtors_alive = false;<br>
// Used to trigger destructors on thread exit; value is ignored<br>
- pthread_key_t dtors_key;<br>
+ __libcxxabi_tls_key dtors_key;<br>
<br>
void run_dtors(void*) {<br>
while (auto head = dtors) {<br>
@@ -79,16 +80,16 @@ namespace {<br>
<br>
struct DtorsManager {<br>
DtorsManager() {<br>
- // There is intentionally no matching pthread_key_delete call, as<br>
+ // There is intentionally no matching __libcxxabi_tls_delete call, as<br>
// __cxa_thread_atexit() may be called arbitrarily late (for example, from<br>
// global destructors or atexit() handlers).<br>
- if (pthread_key_create(&dtors_<wbr>key, run_dtors) != 0) {<br>
- abort_message("pthread_key_<wbr>create() failed in __cxa_thread_atexit()");<br>
+ if (__libcxxabi_tls_create(&<wbr>dtors_key, run_dtors) != 0) {<br>
+ abort_message("__libcxxabi_<wbr>tls_create() failed in __cxa_thread_atexit()");<br>
}<br>
}<br>
<br>
~DtorsManager() {<br>
- // pthread_key destructors do not run on threads that call exit()<br>
+ // __libcxxabi_tls_key destructors do not run on threads that call exit()<br>
// (including when the main thread returns from main()), so we explicitly<br>
// call the destructor here. This runs at exit time (potentially earlier<br>
// if libc++abi is dlclose()'d). Any thread_locals initialized after this<br>
@@ -109,12 +110,12 @@ extern "C" {<br>
if (__cxa_thread_atexit_impl) {<br>
return __cxa_thread_atexit_impl(dtor, obj, dso_symbol);<br>
} else {<br>
- // Initialize the dtors pthread_key (uses __cxa_guard_*() for one-time<br>
- // initialization and __cxa_atexit() for destruction)<br>
+ // Initialize the dtors __libcxxabi_tls_key (uses __cxa_guard_*() for<br>
+ // one-time initialization and __cxa_atexit() for destruction)<br>
static DtorsManager manager;<br>
<br>
if (!dtors_alive) {<br>
- if (pthread_setspecific(dtors_<wbr>key, &dtors_key) != 0) {<br>
+ if (__libcxxabi_tls_set(dtors_<wbr>key, &dtors_key) != 0) {<br>
return -1;<br>
}<br>
dtors_alive = true;<br>
<br>
Modified: libcxxabi/trunk/src/fallback_<wbr>malloc.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/fallback_malloc.cpp?rev=284128&r1=284127&r2=284128&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/libcxxabi/trunk/src/<wbr>fallback_malloc.cpp?rev=<wbr>284128&r1=284127&r2=284128&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- libcxxabi/trunk/src/fallback_<wbr>malloc.cpp (original)<br>
+++ libcxxabi/trunk/src/fallback_<wbr>malloc.cpp Thu Oct 13 10:05:19 2016<br>
@@ -10,14 +10,11 @@<br>
#include "fallback_malloc.h"<br>
<br>
#include "config.h"<br>
+#include "threading_support.h"<br>
<br>
#include <cstdlib> // for malloc, calloc, free<br>
#include <cstring> // for memset<br>
<br>
-#ifndef _LIBCXXABI_HAS_NO_THREADS<br>
-#include <pthread.h> // for mutexes<br>
-#endif<br>
-<br>
// A small, simple heap manager based (loosely) on<br>
// the startup heap manager from FreeBSD, optimized for space.<br>
//<br>
@@ -32,7 +29,7 @@ namespace {<br>
<br>
// When POSIX threads are not available, make the mutex operations a nop<br>
#ifndef _LIBCXXABI_HAS_NO_THREADS<br>
-static pthread_mutex_t heap_mutex = PTHREAD_MUTEX_INITIALIZER;<br>
+static __libcxxabi_mutex_t heap_mutex = _LIBCXXABI_MUTEX_INITIALIZER;<br>
#else<br>
static void * heap_mutex = 0;<br>
#endif<br>
@@ -40,8 +37,8 @@ static void * heap_mutex = 0;<br>
class mutexor {<br>
public:<br>
#ifndef _LIBCXXABI_HAS_NO_THREADS<br>
- mutexor ( pthread_mutex_t *m ) : mtx_(m) { pthread_mutex_lock ( mtx_ ); }<br>
- ~mutexor () { pthread_mutex_unlock ( mtx_ ); }<br>
+ mutexor ( __libcxxabi_mutex_t *m ) : mtx_(m) { __libcxxabi_mutex_lock ( mtx_ ); }<br>
+ ~mutexor () { __libcxxabi_mutex_unlock ( mtx_ ); }<br>
#else<br>
mutexor ( void * ) {}<br>
~mutexor () {}<br>
@@ -50,7 +47,7 @@ private:<br>
mutexor ( const mutexor &rhs );<br>
mutexor & operator = ( const mutexor &rhs );<br>
#ifndef _LIBCXXABI_HAS_NO_THREADS<br>
- pthread_mutex_t *mtx_;<br>
+ __libcxxabi_mutex_t *mtx_;<br>
#endif<br>
};<br>
<br>
<br>
Added: libcxxabi/trunk/src/threading_<wbr>support.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/threading_support.h?rev=284128&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/libcxxabi/trunk/src/<wbr>threading_support.h?rev=<wbr>284128&view=auto</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- libcxxabi/trunk/src/threading_<wbr>support.h (added)<br>
+++ libcxxabi/trunk/src/threading_<wbr>support.h Thu Oct 13 10:05:19 2016<br>
@@ -0,0 +1,107 @@<br>
+//===------------------------ threading_support.h -------------------------===//<br>
+//<br>
+// The LLVM Compiler Infrastructure<br>
+//<br>
+// This file is dual licensed under the MIT and the University of Illinois Open<br>
+// Source Licenses. See LICENSE.TXT for details.<br>
+//<br>
+//===------------------------<wbr>------------------------------<wbr>----------------===//<br>
+<br>
+#ifndef _LIBCXXABI_THREADING_SUPPORT_H<br>
+#define _LIBCXXABI_THREADING_SUPPORT_H<br>
+<br>
+#include "__cxxabi_config.h"<br>
+#include "config.h"<br>
+<br>
+#ifndef _LIBCXXABI_HAS_NO_THREADS<br>
+<br>
+#if defined(_LIBCXXABI_USE_THREAD_<wbr>API_PTHREAD)<br>
+#include <pthread.h><br>
+<br>
+#define _LIBCXXABI_THREAD_ABI_<wbr>VISIBILITY inline _LIBCXXABI_INLINE_VISIBILITY<br>
+<br>
+// Mutex<br>
+typedef pthread_mutex_t __libcxxabi_mutex_t;<br>
+#define _LIBCXXABI_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER<br>
+<br>
+_LIBCXXABI_THREAD_ABI_<wbr>VISIBILITY<br>
+int __libcxxabi_mutex_lock(__<wbr>libcxxabi_mutex_t *mutex) {<br>
+ return pthread_mutex_lock(mutex);<br>
+}<br>
+<br>
+_LIBCXXABI_THREAD_ABI_<wbr>VISIBILITY<br>
+int __libcxxabi_mutex_unlock(__<wbr>libcxxabi_mutex_t *mutex) {<br>
+ return pthread_mutex_unlock(mutex);<br>
+}<br>
+<br>
+// Condition variable<br>
+typedef pthread_cond_t __libcxxabi_condvar_t;<br>
+#define _LIBCXXABI_CONDVAR_INITIALIZER PTHREAD_COND_INITIALIZER<br>
+<br>
+_LIBCXXABI_THREAD_ABI_<wbr>VISIBILITY<br>
+int __libcxxabi_condvar_wait(__<wbr>libcxxabi_condvar_t *cv,<br>
+ __libcxxabi_mutex_t *mutex) {<br>
+ return pthread_cond_wait(cv, mutex);<br>
+}<br>
+<br>
+_LIBCXXABI_THREAD_ABI_<wbr>VISIBILITY<br>
+int __libcxxabi_condvar_broadcast(<wbr>__libcxxabi_condvar_t *cv) {<br>
+ return pthread_cond_broadcast(cv);<br>
+}<br>
+<br>
+// Execute once<br>
+typedef pthread_once_t __libcxxabi_exec_once_flag;<br>
+#define _LIBCXXABI_EXEC_ONCE_<wbr>INITIALIZER PTHREAD_ONCE_INIT<br>
+<br>
+_LIBCXXABI_THREAD_ABI_<wbr>VISIBILITY<br>
+int __libcxxabi_execute_once(__<wbr>libcxxabi_exec_once_flag *flag,<br>
+ void (*init_routine)(void)) {<br>
+ return pthread_once(flag, init_routine);<br>
+}<br>
+<br>
+// Thread id<br>
+#if defined(__APPLE__) && !defined(__arm__)<br>
+_LIBCXXABI_THREAD_ABI_<wbr>VISIBILITY<br>
+mach_port_t __libcxxabi_thread_get_port()<br>
+{<br>
+ return pthread_mach_thread_np(<wbr>pthread_self());<br>
+}<br>
+#endif<br>
+<br>
+// Thread<br>
+typedef pthread_t __libcxxabi_thread_t;<br>
+<br>
+_LIBCXXABI_THREAD_ABI_<wbr>VISIBILITY<br>
+int __libcxxabi_thread_create(__<wbr>libcxxabi_thread_t* __t,<br>
+ void* (*__func)(void*), void* __arg)<br>
+{<br>
+ return pthread_create(__t, 0, __func, __arg);<br>
+}<br>
+<br>
+_LIBCXXABI_THREAD_ABI_<wbr>VISIBILITY<br>
+int __libcxxabi_thread_join(__<wbr>libcxxabi_thread_t* __t)<br>
+{<br>
+ return pthread_join(*__t, 0);<br>
+}<br>
+<br>
+// TLS<br>
+typedef pthread_key_t __libcxxabi_tls_key;<br>
+<br>
+_LIBCXXABI_THREAD_ABI_<wbr>VISIBILITY<br>
+int __libcxxabi_tls_create(__<wbr>libcxxabi_tls_key *key,<br>
+ void (*destructor)(void *)) {<br>
+ return pthread_key_create(key, destructor);<br>
+}<br>
+<br>
+_LIBCXXABI_THREAD_ABI_<wbr>VISIBILITY<br>
+void *__libcxxabi_tls_get(__<wbr>libcxxabi_tls_key key) {<br>
+ return pthread_getspecific(key);<br>
+}<br>
+<br>
+_LIBCXXABI_THREAD_ABI_<wbr>VISIBILITY<br>
+int __libcxxabi_tls_set(__<wbr>libcxxabi_tls_key key, void *value) {<br>
+ return pthread_setspecific(key, value);<br>
+}<br>
+#endif // _LIBCXXABI_USE_THREAD_API_<wbr>PTHREAD<br>
+#endif // !_LIBCXXABI_HAS_NO_THREADS<br>
+#endif // _LIBCXXABI_THREADING_SUPPORT_H<br>
<br>
Modified: libcxxabi/trunk/test/test_<wbr>exception_storage.pass.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/test/test_exception_storage.pass.cpp?rev=284128&r1=284127&r2=284128&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/libcxxabi/trunk/test/<wbr>test_exception_storage.pass.<wbr>cpp?rev=284128&r1=284127&r2=<wbr>284128&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- libcxxabi/trunk/test/test_<wbr>exception_storage.pass.cpp (original)<br>
+++ libcxxabi/trunk/test/test_<wbr>exception_storage.pass.cpp Thu Oct 13 10:05:19 2016<br>
@@ -12,9 +12,7 @@<br>
#include <cstdlib><br>
#include <algorithm><br>
#include <iostream><br>
-#ifndef _LIBCXXABI_HAS_NO_THREADS<br>
-# include <pthread.h><br>
-#endif<br>
+#include "../src/threading_support.h"<br>
#include <unistd.h><br>
<br>
#include "../src/cxa_exception.hpp"<br>
@@ -40,8 +38,8 @@ void *thread_code (void *parm) {<br>
<br>
#ifndef _LIBCXXABI_HAS_NO_THREADS<br>
#define NUMTHREADS 10<br>
-size_t thread_globals [ NUMTHREADS ] = { 0 };<br>
-pthread_t threads [ NUMTHREADS ];<br>
+size_t thread_globals [ NUMTHREADS ] = { 0 };<br>
+__libcxxabi_thread_t threads [ NUMTHREADS ];<br>
#endif<br>
<br>
int main ( int argc, char *argv [] ) {<br>
@@ -50,9 +48,9 @@ int main ( int argc, char *argv [] ) {<br>
#ifndef _LIBCXXABI_HAS_NO_THREADS<br>
// Make the threads, let them run, and wait for them to finish<br>
for ( int i = 0; i < NUMTHREADS; ++i )<br>
- pthread_create( threads + i, NULL, thread_code, (void *) (thread_globals + i));<br>
+ __libcxxabi_thread_create ( threads + i, thread_code, (void *) (thread_globals + i));<br>
for ( int i = 0; i < NUMTHREADS; ++i )<br>
- pthread_join ( threads [ i ], NULL );<br>
+ __libcxxabi_thread_join ( &threads [ i ] );<br>
<br>
for ( int i = 0; i < NUMTHREADS; ++i )<br>
if ( 0 == thread_globals [ i ] ) {<br>
<br>
Modified: libcxxabi/trunk/test/test_<wbr>fallback_malloc.pass.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/test/test_fallback_malloc.pass.cpp?rev=284128&r1=284127&r2=284128&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/libcxxabi/trunk/test/<wbr>test_fallback_malloc.pass.cpp?<wbr>rev=284128&r1=284127&r2=<wbr>284128&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- libcxxabi/trunk/test/test_<wbr>fallback_malloc.pass.cpp (original)<br>
+++ libcxxabi/trunk/test/test_<wbr>fallback_malloc.pass.cpp Thu Oct 13 10:05:19 2016<br>
@@ -10,7 +10,7 @@<br>
#include <iostream><br>
#include <deque><br>
<br>
-#include <pthread.h><br>
+#include "../src/threading_support.h"<br>
<br>
typedef std::deque<void *> container;<br>
<br>
<br>
<br>
______________________________<wbr>_________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div>