[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
This commit is contained in:
Asiri Rathnayake 2016-09-21 09:09:32 +00:00
parent 099771b736
commit 7c98baab29
9 changed files with 47 additions and 62 deletions

View File

@ -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)

View File

@ -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.

View File

@ -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"

View File

@ -15,7 +15,7 @@
#include "config.h"
#if LIBCXXABI_HAS_NO_THREADS
#if defined(_LIBCXXABI_HAS_NO_THREADS)
namespace __cxxabiv1 {
extern "C" {

View File

@ -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_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"

View File

@ -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
};

View File

@ -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):

View File

@ -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;
}

View File

@ -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