[libcxxabi] r282062 - [libcxxabi] cleanup the use of LIBCXXABI_HAS_NO_THREADS macro (NFC)
Asiri Rathnayake via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 21 02:09:32 PDT 2016
Author: asiri
Date: Wed Sep 21 04:09:32 2016
New Revision: 282062
URL: http://llvm.org/viewvc/llvm-project?rev=282062&view=rev
Log:
[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.
Modified:
libcxxabi/trunk/CMakeLists.txt
libcxxabi/trunk/src/config.h
libcxxabi/trunk/src/cxa_exception.cpp
libcxxabi/trunk/src/cxa_exception_storage.cpp
libcxxabi/trunk/src/cxa_guard.cpp
libcxxabi/trunk/src/fallback_malloc.ipp
libcxxabi/trunk/test/libcxxabi/test/config.py
libcxxabi/trunk/test/test_exception_storage.pass.cpp
libcxxabi/trunk/test/test_guard.pass.cpp
Modified: libcxxabi/trunk/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/CMakeLists.txt?rev=282062&r1=282061&r2=282062&view=diff
==============================================================================
--- libcxxabi/trunk/CMakeLists.txt (original)
+++ libcxxabi/trunk/CMakeLists.txt Wed Sep 21 04:09:32 2016
@@ -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)
Modified: libcxxabi/trunk/src/config.h
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/config.h?rev=282062&r1=282061&r2=282062&view=diff
==============================================================================
--- libcxxabi/trunk/src/config.h (original)
+++ libcxxabi/trunk/src/config.h Wed Sep 21 04:09:32 2016
@@ -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.
Modified: libcxxabi/trunk/src/cxa_exception.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/cxa_exception.cpp?rev=282062&r1=282061&r2=282062&view=diff
==============================================================================
--- libcxxabi/trunk/src/cxa_exception.cpp (original)
+++ libcxxabi/trunk/src/cxa_exception.cpp Wed Sep 21 04:09:32 2016
@@ -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"
Modified: libcxxabi/trunk/src/cxa_exception_storage.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/cxa_exception_storage.cpp?rev=282062&r1=282061&r2=282062&view=diff
==============================================================================
--- libcxxabi/trunk/src/cxa_exception_storage.cpp (original)
+++ libcxxabi/trunk/src/cxa_exception_storage.cpp Wed Sep 21 04:09:32 2016
@@ -15,7 +15,7 @@
#include "config.h"
-#if LIBCXXABI_HAS_NO_THREADS
+#if defined(_LIBCXXABI_HAS_NO_THREADS)
namespace __cxxabiv1 {
extern "C" {
Modified: libcxxabi/trunk/src/cxa_guard.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/cxa_guard.cpp?rev=282062&r1=282061&r2=282062&view=diff
==============================================================================
--- libcxxabi/trunk/src/cxa_guard.cpp (original)
+++ libcxxabi/trunk/src/cxa_guard.cpp Wed Sep 21 04:09:32 2016
@@ -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 @@ void set_initialized(guard_type* guard_o
}
#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_ob
#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_abo
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"
Modified: libcxxabi/trunk/src/fallback_malloc.ipp
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/fallback_malloc.ipp?rev=282062&r1=282061&r2=282062&view=diff
==============================================================================
--- libcxxabi/trunk/src/fallback_malloc.ipp (original)
+++ libcxxabi/trunk/src/fallback_malloc.ipp Wed Sep 21 04:09:32 2016
@@ -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
};
Modified: libcxxabi/trunk/test/libcxxabi/test/config.py
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/test/libcxxabi/test/config.py?rev=282062&r1=282061&r2=282062&view=diff
==============================================================================
--- libcxxabi/trunk/test/libcxxabi/test/config.py (original)
+++ libcxxabi/trunk/test/libcxxabi/test/config.py Wed Sep 21 04:09:32 2016
@@ -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):
Modified: libcxxabi/trunk/test/test_exception_storage.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/test/test_exception_storage.pass.cpp?rev=282062&r1=282061&r2=282062&view=diff
==============================================================================
--- libcxxabi/trunk/test/test_exception_storage.pass.cpp (original)
+++ libcxxabi/trunk/test/test_exception_storage.pass.cpp Wed Sep 21 04:09:32 2016
@@ -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 @@ 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;
+}
Modified: libcxxabi/trunk/test/test_guard.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/test/test_guard.pass.cpp?rev=282062&r1=282061&r2=282062&view=diff
==============================================================================
--- libcxxabi/trunk/test/test_guard.pass.cpp (original)
+++ libcxxabi/trunk/test/test_guard.pass.cpp Wed Sep 21 04:09:32 2016
@@ -12,7 +12,7 @@
#include <cassert>
-#if !LIBCXXABI_HAS_NO_THREADS
+#ifndef _LIBCXXABI_HAS_NO_THREADS
#include <thread>
#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
More information about the cfe-commits
mailing list