diff options
author | Jonathan Roelofs <jonathan@codesourcery.com> | 2014-05-06 21:30:56 +0000 |
---|---|---|
committer | Jonathan Roelofs <jonathan@codesourcery.com> | 2014-05-06 21:30:56 +0000 |
commit | 40e9842854430ff34b0b687cbb94e9f4a044588a (patch) | |
tree | 6f9cfaa242398ebcd758477ff08448196d64ebaf /libcxxabi/src | |
parent | 9c928478f48384ad641a3c895856fbcef0c34f22 (diff) | |
download | bcm5719-llvm-40e9842854430ff34b0b687cbb94e9f4a044588a.tar.gz bcm5719-llvm-40e9842854430ff34b0b687cbb94e9f4a044588a.zip |
On single threaded systems, turn mutexes into nops
http://reviews.llvm.org/D3386
llvm-svn: 208135
Diffstat (limited to 'libcxxabi/src')
-rw-r--r-- | libcxxabi/src/config.h | 25 | ||||
-rw-r--r-- | libcxxabi/src/cxa_exception.cpp | 6 | ||||
-rw-r--r-- | libcxxabi/src/cxa_exception_storage.cpp | 14 | ||||
-rw-r--r-- | libcxxabi/src/cxa_guard.cpp | 29 | ||||
-rw-r--r-- | libcxxabi/src/fallback_malloc.ipp | 14 |
5 files changed, 83 insertions, 5 deletions
diff --git a/libcxxabi/src/config.h b/libcxxabi/src/config.h new file mode 100644 index 00000000000..72894471231 --- /dev/null +++ b/libcxxabi/src/config.h @@ -0,0 +1,25 @@ +//===----------------------------- config.h -------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +// +// Defines macros used within the libc++abi project. +// +//===----------------------------------------------------------------------===// + + +#ifndef LIBCXXABI_CONFIG_H +#define LIBCXXABI_CONFIG_H + +#include <unistd.h> + +#if defined(_POSIX_THREADS) && _POSIX_THREADS > 0 +# define LIBCXXABI_SINGLE_THREADED 0 +#else +# define LIBCXXABI_SINGLE_THREADED 1 +#endif + +#endif // LIBCXXABI_CONFIG_H diff --git a/libcxxabi/src/cxa_exception.cpp b/libcxxabi/src/cxa_exception.cpp index 64040fd6885..9bc6ad6fd04 100644 --- a/libcxxabi/src/cxa_exception.cpp +++ b/libcxxabi/src/cxa_exception.cpp @@ -11,13 +11,15 @@ // //===----------------------------------------------------------------------===// +#include "config.h" #include "cxxabi.h" #include <exception> // for std::terminate #include <cstdlib> // for malloc, free #include <cstring> // for memset -#include <pthread.h> - +#if !LIBCXXABI_SINGLE_THREADED +# include <pthread.h> // for fallback_malloc.ipp's mutexes +#endif #include "cxa_exception.hpp" #include "cxa_handlers.hpp" diff --git a/libcxxabi/src/cxa_exception_storage.cpp b/libcxxabi/src/cxa_exception_storage.cpp index c3ee8565da4..6f902c68873 100644 --- a/libcxxabi/src/cxa_exception_storage.cpp +++ b/libcxxabi/src/cxa_exception_storage.cpp @@ -13,7 +13,19 @@ #include "cxa_exception.hpp" -#ifdef HAS_THREAD_LOCAL +#include "config.h" + +#if LIBCXXABI_SINGLE_THREADED + +namespace __cxxabiv1 { +extern "C" { + static __cxa_eh_globals eh_globals; + __cxa_eh_globals *__cxa_get_globals() { return &eh_globals; } + __cxa_eh_globals *__cxa_get_globals_fast() { return &eh_globals; } + } +} + +#elif defined(HAS_THREAD_LOCAL) namespace __cxxabiv1 { diff --git a/libcxxabi/src/cxa_guard.cpp b/libcxxabi/src/cxa_guard.cpp index e403b64abd5..b22fcbbd86e 100644 --- a/libcxxabi/src/cxa_guard.cpp +++ b/libcxxabi/src/cxa_guard.cpp @@ -8,8 +8,11 @@ //===----------------------------------------------------------------------===// #include "abort_message.h" +#include "config.h" -#include <pthread.h> +#if !LIBCXXABI_SINGLE_THREADED +# include <pthread.h> +#endif #include <stdint.h> /* @@ -59,8 +62,10 @@ void set_initialized(guard_type* guard_object) { #endif +#if !LIBCXXABI_SINGLE_THREADED pthread_mutex_t guard_mut = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t guard_cv = PTHREAD_COND_INITIALIZER; +#endif #if defined(__APPLE__) && !defined(__arm__) @@ -161,9 +166,27 @@ set_lock(uint32_t& x, lock_type y) extern "C" { +#if LIBCXXABI_SINGLE_THREADED +int __cxa_guard_acquire(guard_type* guard_object) +{ + return !is_initialized(guard_object); +} + +void __cxa_guard_release(guard_type* guard_object) +{ + *guard_object = 0; + set_initialized(guard_object); +} + +void __cxa_guard_abort(guard_type* guard_object) +{ + *guard_object = 0; +} + +#else // !LIBCXXABI_SINGLE_THREADED + int __cxa_guard_acquire(guard_type* guard_object) { - char* initialized = (char*)guard_object; if (pthread_mutex_lock(&guard_mut)) abort_message("__cxa_guard_acquire failed to acquire mutex"); int result = *initialized == 0; @@ -226,6 +249,8 @@ void __cxa_guard_abort(guard_type* guard_object) abort_message("__cxa_guard_abort failed to broadcast condition variable"); } +#endif // !LIBCXXABI_SINGLE_THREADED + } // extern "C" } // __cxxabiv1 diff --git a/libcxxabi/src/fallback_malloc.ipp b/libcxxabi/src/fallback_malloc.ipp index 4f8ce903ed2..a97f3fd45f2 100644 --- a/libcxxabi/src/fallback_malloc.ipp +++ b/libcxxabi/src/fallback_malloc.ipp @@ -11,6 +11,8 @@ // //===----------------------------------------------------------------------===// +#include "config.h" + // A small, simple heap manager based (loosely) on // the startup heap manager from FreeBSD, optimized for space. // @@ -23,16 +25,28 @@ namespace { +// When POSIX threads are not available, make the mutex operations a nop +#if LIBCXXABI_SINGLE_THREADED +static void * heap_mutex = 0; +#else static pthread_mutex_t heap_mutex = PTHREAD_MUTEX_INITIALIZER; +#endif class mutexor { public: +#if LIBCXXABI_SINGLE_THREADED + mutexor ( void * ) {} + ~mutexor () {} +#else mutexor ( pthread_mutex_t *m ) : mtx_(m) { pthread_mutex_lock ( mtx_ ); } ~mutexor () { pthread_mutex_unlock ( mtx_ ); } +#endif private: mutexor ( const mutexor &rhs ); mutexor & operator = ( const mutexor &rhs ); +#if !LIBCXXABI_SINGLE_THREADED pthread_mutex_t *mtx_; +#endif }; |