[libcxxabi] r219012 - Use __atomic_exchange_n instead of Clang's __sync_swap

Reid Kleckner reid at kleckner.net
Fri Oct 3 13:03:47 PDT 2014


Author: rnk
Date: Fri Oct  3 15:03:47 2014
New Revision: 219012

URL: http://llvm.org/viewvc/llvm-project?rev=219012&view=rev
Log:
Use __atomic_exchange_n instead of Clang's __sync_swap

Also remove an extra extern "C" from a global variable redeclaration.
This allows building libcxxabi with GCC on my system.

Reviewers: majnemer

Differential Revision: http://reviews.llvm.org/D5604

Modified:
    libcxxabi/trunk/src/cxa_default_handlers.cpp
    libcxxabi/trunk/src/cxa_handlers.cpp

Modified: libcxxabi/trunk/src/cxa_default_handlers.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/cxa_default_handlers.cpp?rev=219012&r1=219011&r2=219012&view=diff
==============================================================================
--- libcxxabi/trunk/src/cxa_default_handlers.cpp (original)
+++ libcxxabi/trunk/src/cxa_default_handlers.cpp Fri Oct  3 15:03:47 2014
@@ -101,9 +101,10 @@ namespace std
 unexpected_handler
 set_unexpected(unexpected_handler func) _NOEXCEPT
 {
-	if (func == 0)
-		func = default_unexpected_handler;
-	return __sync_swap(&__cxa_unexpected_handler, func);
+    if (func == 0)
+        func = default_unexpected_handler;
+    return __atomic_exchange_n(&__cxa_unexpected_handler, func,
+                               __ATOMIC_ACQ_REL);
 //  Using of C++11 atomics this should be rewritten
 //  return __cxa_unexpected_handler.exchange(func, memory_order_acq_rel);
 }
@@ -111,9 +112,10 @@ set_unexpected(unexpected_handler func)
 terminate_handler
 set_terminate(terminate_handler func) _NOEXCEPT
 {
-	if (func == 0)
-		func = default_terminate_handler;
-	return __sync_swap(&__cxa_terminate_handler, func);
+    if (func == 0)
+        func = default_terminate_handler;
+    return __atomic_exchange_n(&__cxa_terminate_handler, func,
+                               __ATOMIC_ACQ_REL);
 //  Using of C++11 atomics this should be rewritten
 //  return __cxa_terminate_handler.exchange(func, memory_order_acq_rel);
 }

Modified: libcxxabi/trunk/src/cxa_handlers.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/cxa_handlers.cpp?rev=219012&r1=219011&r2=219012&view=diff
==============================================================================
--- libcxxabi/trunk/src/cxa_handlers.cpp (original)
+++ libcxxabi/trunk/src/cxa_handlers.cpp Fri Oct  3 15:03:47 2014
@@ -102,14 +102,14 @@ terminate() _NOEXCEPT
     __terminate(get_terminate());
 }
 
-extern "C" new_handler __cxa_new_handler = 0;
+new_handler __cxa_new_handler = 0;
 // In the future these will become:
 // std::atomic<std::new_handler>  __cxa_new_handler(0);
 
 new_handler
 set_new_handler(new_handler handler) _NOEXCEPT
 {
-    return __sync_swap(&__cxa_new_handler, handler);
+    return __atomic_exchange_n(&__cxa_new_handler, handler, __ATOMIC_ACQ_REL);
 //  Using of C++11 atomics this should be rewritten
 //  return __cxa_new_handler.exchange(handler, memory_order_acq_rel);
 }





More information about the cfe-commits mailing list