rmaprath created this revision.
rmaprath added reviewers: mclow.lists, EricWF.
rmaprath added a subscriber: cfe-commits.
Herald added subscribers: mgorny, beanz.

Align the naming / use of the macro ``LIBCXXABI_HAS_NO_THREADS`` to follow what 
we have in `libcxx`.

This change is mostly NFC, thought of putting it up for review as it involves a 
change in naming, and sometimes that can cause disagreements.

Will commit if there isn't much interest.

https://reviews.llvm.org/D24770

Files:
  CMakeLists.txt
  src/config.h
  src/cxa_exception.cpp
  src/cxa_exception_storage.cpp
  src/cxa_guard.cpp
  src/fallback_malloc.ipp
  test/libcxxabi/test/config.py
  test/test_exception_storage.pass.cpp
  test/test_guard.pass.cpp

Index: test/test_guard.pass.cpp
===================================================================
--- test/test_guard.pass.cpp
+++ test/test_guard.pass.cpp
@@ -12,7 +12,7 @@
 
 #include <cassert>
 
-#if !LIBCXXABI_HAS_NO_THREADS
+#ifndef _LIBCXXABI_HAS_NO_THREADS
 #include <thread>
 #endif
 
@@ -80,7 +80,7 @@
     }
 }
 
-#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 @@
         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
Index: test/test_exception_storage.pass.cpp
===================================================================
--- test/test_exception_storage.pass.cpp
+++ test/test_exception_storage.pass.cpp
@@ -12,7 +12,7 @@
 #include <cstdlib>
 #include <algorithm>
 #include <iostream>
-#if !LIBCXXABI_HAS_NO_THREADS
+#ifndef _LIBCXXABI_HAS_NO_THREADS
 #  include <pthread.h>
 #endif
 #include <unistd.h>
@@ -38,29 +38,16 @@
     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 @@
             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;
+}
Index: test/libcxxabi/test/config.py
===================================================================
--- test/libcxxabi/test/config.py
+++ test/libcxxabi/test/config.py
@@ -47,7 +47,7 @@
         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):
Index: src/fallback_malloc.ipp
===================================================================
--- src/fallback_malloc.ipp
+++ 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
     };
Index: src/cxa_guard.cpp
===================================================================
--- src/cxa_guard.cpp
+++ 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 <pthread.h>
 #endif
 #include <stdint.h>
@@ -50,7 +50,7 @@
 }
 #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 @@
 #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 @@
 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 @@
         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"
 
Index: src/cxa_exception_storage.cpp
===================================================================
--- src/cxa_exception_storage.cpp
+++ 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" {
Index: src/cxa_exception.cpp
===================================================================
--- src/cxa_exception.cpp
+++ src/cxa_exception.cpp
@@ -17,7 +17,7 @@
 #include <exception>        // for std::terminate
 #include <cstdlib>          // for malloc, free
 #include <cstring>          // for memset
-#if !LIBCXXABI_HAS_NO_THREADS
+#ifndef _LIBCXXABI_HAS_NO_THREADS
 #  include <pthread.h>      // for fallback_malloc.ipp's mutexes
 #endif
 #include "cxa_exception.hpp"
Index: src/config.h
===================================================================
--- src/config.h
+++ src/config.h
@@ -16,11 +16,6 @@
 
 #include <unistd.h>
 
-// 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.
Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -326,7 +326,7 @@
                         " 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)
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to