From 7c98baab29f8ade4b0f69d482f9ce0bef4063b65 Mon Sep 17 00:00:00 2001 From: Asiri Rathnayake Date: Wed, 21 Sep 2016 09:09:32 +0000 Subject: [PATCH] [libcxxabi] cleanup the use of LIBCXXABI_HAS_NO_THREADS macro (NFC) Align the naming / use of the macro LIBCXXABI_HAS_NO_THREADS to follow what we have in libcxx. NFC. llvm-svn: 282062 --- libcxxabi/CMakeLists.txt | 2 +- libcxxabi/src/config.h | 5 --- libcxxabi/src/cxa_exception.cpp | 2 +- libcxxabi/src/cxa_exception_storage.cpp | 2 +- libcxxabi/src/cxa_guard.cpp | 40 +++++++++---------- libcxxabi/src/fallback_malloc.ipp | 16 ++++---- libcxxabi/test/libcxxabi/test/config.py | 2 +- .../test/test_exception_storage.pass.cpp | 32 +++++---------- libcxxabi/test/test_guard.pass.cpp | 8 ++-- 9 files changed, 47 insertions(+), 62 deletions(-) diff --git a/libcxxabi/CMakeLists.txt b/libcxxabi/CMakeLists.txt index 82064ede8f74..e1487b3156fe 100644 --- a/libcxxabi/CMakeLists.txt +++ b/libcxxabi/CMakeLists.txt @@ -326,7 +326,7 @@ if (NOT LIBCXXABI_ENABLE_THREADS) " be set to ON when LIBCXXABI_ENABLE_THREADS" " is also set to ON.") endif() - add_definitions(-DLIBCXXABI_HAS_NO_THREADS=1) + add_definitions(-D_LIBCXXABI_HAS_NO_THREADS) endif() if (LIBCXXABI_HAS_PTHREAD_API) diff --git a/libcxxabi/src/config.h b/libcxxabi/src/config.h index ac6d297d113a..5d38d4d14655 100644 --- a/libcxxabi/src/config.h +++ b/libcxxabi/src/config.h @@ -16,11 +16,6 @@ #include -// Set this in the CXXFLAGS when you need it -#if !defined(LIBCXXABI_HAS_NO_THREADS) -# define LIBCXXABI_HAS_NO_THREADS 0 -#endif - // Set this in the CXXFLAGS when you need it, because otherwise we'd have to // #if !defined(__linux__) && !defined(__APPLE__) && ... // and so-on for *every* platform. diff --git a/libcxxabi/src/cxa_exception.cpp b/libcxxabi/src/cxa_exception.cpp index 50d1a468cea2..603f869f9889 100644 --- a/libcxxabi/src/cxa_exception.cpp +++ b/libcxxabi/src/cxa_exception.cpp @@ -17,7 +17,7 @@ #include // for std::terminate #include // for malloc, free #include // for memset -#if !LIBCXXABI_HAS_NO_THREADS +#ifndef _LIBCXXABI_HAS_NO_THREADS # include // for fallback_malloc.ipp's mutexes #endif #include "cxa_exception.hpp" diff --git a/libcxxabi/src/cxa_exception_storage.cpp b/libcxxabi/src/cxa_exception_storage.cpp index a39b6db005f9..235b0cf1dd3b 100644 --- a/libcxxabi/src/cxa_exception_storage.cpp +++ b/libcxxabi/src/cxa_exception_storage.cpp @@ -15,7 +15,7 @@ #include "config.h" -#if LIBCXXABI_HAS_NO_THREADS +#if defined(_LIBCXXABI_HAS_NO_THREADS) namespace __cxxabiv1 { extern "C" { diff --git a/libcxxabi/src/cxa_guard.cpp b/libcxxabi/src/cxa_guard.cpp index 2a01f27ad99d..253d5d4ec5c4 100644 --- a/libcxxabi/src/cxa_guard.cpp +++ b/libcxxabi/src/cxa_guard.cpp @@ -12,7 +12,7 @@ #include "abort_message.h" #include "config.h" -#if !LIBCXXABI_HAS_NO_THREADS +#ifndef _LIBCXXABI_HAS_NO_THREADS # include #endif #include @@ -50,7 +50,7 @@ void set_initialized(guard_type* guard_object) { } #endif -#if LIBCXXABI_HAS_NO_THREADS || (defined(__APPLE__) && !defined(__arm__)) +#if defined(_LIBCXXABI_HAS_NO_THREADS) || (defined(__APPLE__) && !defined(__arm__)) #ifdef __arm__ // Test the lowest bit. @@ -68,7 +68,7 @@ bool is_initialized(guard_type* guard_object) { #endif #endif -#if !LIBCXXABI_HAS_NO_THREADS +#ifndef _LIBCXXABI_HAS_NO_THREADS pthread_mutex_t guard_mut = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t guard_cv = PTHREAD_COND_INITIALIZER; #endif @@ -172,22 +172,7 @@ set_lock(uint32_t& x, lock_type y) extern "C" { -#if LIBCXXABI_HAS_NO_THREADS -_LIBCXXABI_FUNC_VIS int __cxa_guard_acquire(guard_type *guard_object) { - return !is_initialized(guard_object); -} - -_LIBCXXABI_FUNC_VIS void __cxa_guard_release(guard_type *guard_object) { - *guard_object = 0; - set_initialized(guard_object); -} - -_LIBCXXABI_FUNC_VIS void __cxa_guard_abort(guard_type *guard_object) { - *guard_object = 0; -} - -#else // !LIBCXXABI_HAS_NO_THREADS - +#ifndef _LIBCXXABI_HAS_NO_THREADS _LIBCXXABI_FUNC_VIS int __cxa_guard_acquire(guard_type *guard_object) { char* initialized = (char*)guard_object; if (pthread_mutex_lock(&guard_mut)) @@ -250,7 +235,22 @@ _LIBCXXABI_FUNC_VIS void __cxa_guard_abort(guard_type *guard_object) { abort_message("__cxa_guard_abort failed to broadcast condition variable"); } -#endif // !LIBCXXABI_HAS_NO_THREADS +#else // _LIBCXXABI_HAS_NO_THREADS + +_LIBCXXABI_FUNC_VIS int __cxa_guard_acquire(guard_type *guard_object) { + return !is_initialized(guard_object); +} + +_LIBCXXABI_FUNC_VIS void __cxa_guard_release(guard_type *guard_object) { + *guard_object = 0; + set_initialized(guard_object); +} + +_LIBCXXABI_FUNC_VIS void __cxa_guard_abort(guard_type *guard_object) { + *guard_object = 0; +} + +#endif // !_LIBCXXABI_HAS_NO_THREADS } // extern "C" diff --git a/libcxxabi/src/fallback_malloc.ipp b/libcxxabi/src/fallback_malloc.ipp index 71b65bed888d..1d8f8a32ce4a 100644 --- a/libcxxabi/src/fallback_malloc.ipp +++ b/libcxxabi/src/fallback_malloc.ipp @@ -26,25 +26,25 @@ namespace { // When POSIX threads are not available, make the mutex operations a nop -#if LIBCXXABI_HAS_NO_THREADS -static void * heap_mutex = 0; -#else +#ifndef _LIBCXXABI_HAS_NO_THREADS static pthread_mutex_t heap_mutex = PTHREAD_MUTEX_INITIALIZER; +#else +static void * heap_mutex = 0; #endif class mutexor { public: -#if LIBCXXABI_HAS_NO_THREADS - mutexor ( void * ) {} - ~mutexor () {} -#else +#ifndef _LIBCXXABI_HAS_NO_THREADS mutexor ( pthread_mutex_t *m ) : mtx_(m) { pthread_mutex_lock ( mtx_ ); } ~mutexor () { pthread_mutex_unlock ( mtx_ ); } +#else + mutexor ( void * ) {} + ~mutexor () {} #endif private: mutexor ( const mutexor &rhs ); mutexor & operator = ( const mutexor &rhs ); -#if !LIBCXXABI_HAS_NO_THREADS +#ifndef _LIBCXXABI_HAS_NO_THREADS pthread_mutex_t *mtx_; #endif }; diff --git a/libcxxabi/test/libcxxabi/test/config.py b/libcxxabi/test/libcxxabi/test/config.py index c8a6af0f3db5..8b585eb4c898 100644 --- a/libcxxabi/test/libcxxabi/test/config.py +++ b/libcxxabi/test/libcxxabi/test/config.py @@ -47,7 +47,7 @@ class Configuration(LibcxxConfiguration): else: self.cxx.compile_flags += ['-fno-exceptions', '-DLIBCXXABI_HAS_NO_EXCEPTIONS'] if not self.get_lit_bool('enable_threads', True): - self.cxx.compile_flags += ['-DLIBCXXABI_HAS_NO_THREADS=1'] + self.cxx.compile_flags += ['-D_LIBCXXABI_HAS_NO_THREADS'] super(Configuration, self).configure_compile_flags() def configure_compile_flags_header_includes(self): diff --git a/libcxxabi/test/test_exception_storage.pass.cpp b/libcxxabi/test/test_exception_storage.pass.cpp index 0d5deaa37357..908124692814 100644 --- a/libcxxabi/test/test_exception_storage.pass.cpp +++ b/libcxxabi/test/test_exception_storage.pass.cpp @@ -12,7 +12,7 @@ #include #include #include -#if !LIBCXXABI_HAS_NO_THREADS +#ifndef _LIBCXXABI_HAS_NO_THREADS # include #endif #include @@ -38,29 +38,16 @@ void *thread_code (void *parm) { return parm; } -#if !LIBCXXABI_HAS_NO_THREADS +#ifndef _LIBCXXABI_HAS_NO_THREADS #define NUMTHREADS 10 size_t thread_globals [ NUMTHREADS ] = { 0 }; pthread_t threads [ NUMTHREADS ]; #endif -void print_sizes ( size_t *first, size_t *last ) { - std::cout << "{ " << std::hex; - for ( size_t *iter = first; iter != last; ++iter ) - std::cout << *iter << " "; - std::cout << "}" << std::dec << std::endl; - } - int main ( int argc, char *argv [] ) { int retVal = 0; -#if LIBCXXABI_HAS_NO_THREADS - size_t thread_globals; - // Check that __cxa_get_globals() is not NULL. - if (thread_code(&thread_globals) == 0) { - retVal = 1; - } -#else +#ifndef _LIBCXXABI_HAS_NO_THREADS // Make the threads, let them run, and wait for them to finish for ( int i = 0; i < NUMTHREADS; ++i ) pthread_create( threads + i, NULL, thread_code, (void *) (thread_globals + i)); @@ -73,15 +60,18 @@ int main ( int argc, char *argv [] ) { retVal = 1; } -// print_sizes ( thread_globals, thread_globals + NUMTHREADS ); std::sort ( thread_globals, thread_globals + NUMTHREADS ); for ( int i = 1; i < NUMTHREADS; ++i ) if ( thread_globals [ i - 1 ] == thread_globals [ i ] ) { std::cerr << "Duplicate thread globals (" << i-1 << " and " << i << ")" << std::endl; retVal = 2; } -// print_sizes ( thread_globals, thread_globals + NUMTHREADS ); - -#endif - return retVal; +#else // _LIBCXXABI_HAS_NO_THREADS + size_t thread_globals; + // Check that __cxa_get_globals() is not NULL. + if (thread_code(&thread_globals) == 0) { + retVal = 1; } +#endif // !_LIBCXXABI_HAS_NO_THREADS + return retVal; +} diff --git a/libcxxabi/test/test_guard.pass.cpp b/libcxxabi/test/test_guard.pass.cpp index 9b0c2d5ab71e..2312b511a5d0 100644 --- a/libcxxabi/test/test_guard.pass.cpp +++ b/libcxxabi/test/test_guard.pass.cpp @@ -12,7 +12,7 @@ #include -#if !LIBCXXABI_HAS_NO_THREADS +#ifndef _LIBCXXABI_HAS_NO_THREADS #include #endif @@ -80,7 +80,7 @@ namespace test3 { } } -#if !LIBCXXABI_HAS_NO_THREADS +#ifndef _LIBCXXABI_HAS_NO_THREADS // A simple thread test of two threads racing to initialize a variable. This // isn't guaranteed to catch any particular threading problems. namespace test4 { @@ -132,14 +132,14 @@ namespace test5 { assert(run_count == 1); } } -#endif /* LIBCXXABI_HAS_NO_THREADS */ +#endif /* _LIBCXXABI_HAS_NO_THREADS */ int main() { test1::test(); test2::test(); test3::test(); -#if !LIBCXXABI_HAS_NO_THREADS +#ifndef _LIBCXXABI_HAS_NO_THREADS test4::test(); test5::test(); #endif