[cfe-commits] [libcxxabi] r153041 - in /libcxxabi/trunk/src: cxa_default_handlers.cpp cxa_handlers.cpp cxa_handlers.hpp

Howard Hinnant hhinnant at apple.com
Mon Mar 19 09:56:53 PDT 2012


Author: hhinnant
Date: Mon Mar 19 11:56:51 2012
New Revision: 153041

URL: http://llvm.org/viewvc/llvm-project?rev=153041&view=rev
Log:
I would really like to write the handlers in terms of C++11 atomics.  This would give us the best performance, portablity, and safety tradeoff.  Unfortunately I can not yet do that.  So I've put the desired code in comments, and reverted the handler getters to the slower but safer legacy atomic intrinsics.

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

Modified: libcxxabi/trunk/src/cxa_default_handlers.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/cxa_default_handlers.cpp?rev=153041&r1=153040&r2=153041&view=diff
==============================================================================
--- libcxxabi/trunk/src/cxa_default_handlers.cpp (original)
+++ libcxxabi/trunk/src/cxa_default_handlers.cpp Mon Mar 19 11:56:51 2012
@@ -94,6 +94,10 @@
 std::terminate_handler  __cxa_terminate_handler = default_terminate_handler;
 std::unexpected_handler __cxa_unexpected_handler = default_unexpected_handler;
 
+// In the future these will become:
+// std::atomic<std::terminate_handler>  __cxa_terminate_handler(default_terminate_handler);
+// std::atomic<std::unexpected_handler> __cxa_unexpected_handler(default_unexpected_handler);
+
 namespace std
 {
 
@@ -103,6 +107,8 @@
 	if (func == 0)
 		func = default_unexpected_handler;
 	return __sync_swap(&__cxa_unexpected_handler, func);
+//  Using of C++11 atomics this should be rewritten
+//  return __cxa_unexpected_handler.exchange(func, memory_order_acq_rel);
 }
 
 terminate_handler
@@ -111,6 +117,8 @@
 	if (func == 0)
 		func = default_terminate_handler;
 	return __sync_swap(&__cxa_terminate_handler, func);
+//  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=153041&r1=153040&r2=153041&view=diff
==============================================================================
--- libcxxabi/trunk/src/cxa_handlers.cpp (original)
+++ libcxxabi/trunk/src/cxa_handlers.cpp Mon Mar 19 11:56:51 2012
@@ -25,7 +25,10 @@
 unexpected_handler
 get_unexpected() _NOEXCEPT
 {
-    return __cxa_unexpected_handler;
+    return __sync_fetch_and_add(&__cxa_unexpected_handler, (unexpected_handler)0);
+//  The above is safe but overkill on x86
+//  Using of C++11 atomics this should be rewritten
+//  return __cxa_unexpected_handler.load(memory_order_acq);
 }
 
 __attribute__((visibility("hidden"), noreturn))
@@ -47,7 +50,10 @@
 terminate_handler
 get_terminate() _NOEXCEPT
 {
-    return __cxa_terminate_handler;
+    return __sync_fetch_and_add(&__cxa_terminate_handler, (terminate_handler)0);
+//  The above is safe but overkill on x86
+//  Using of C++11 atomics this should be rewritten
+//  return __cxa_terminate_handler.load(memory_order_acq);
 }
 
 __attribute__((visibility("hidden"), noreturn))
@@ -96,17 +102,24 @@
 }
 
 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);
+//  Using of C++11 atomics this should be rewritten
+//  return __cxa_new_handler.exchange(handler, memory_order_acq_rel);
 }
 
 new_handler
 get_new_handler() _NOEXCEPT
 {
-    return __cxa_new_handler;
+    return __sync_fetch_and_add(&__cxa_new_handler, (new_handler)0);
+//  The above is safe but overkill on x86
+//  Using of C++11 atomics this should be rewritten
+//  return __cxa_new_handler.load(memory_order_acq);
 }
 
 }  // std

Modified: libcxxabi/trunk/src/cxa_handlers.hpp
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/cxa_handlers.hpp?rev=153041&r1=153040&r2=153041&view=diff
==============================================================================
--- libcxxabi/trunk/src/cxa_handlers.hpp (original)
+++ libcxxabi/trunk/src/cxa_handlers.hpp Mon Mar 19 11:56:51 2012
@@ -35,6 +35,20 @@
 extern void (*__cxa_unexpected_handler)();
 extern void (*__cxa_new_handler)();
 
+/*
+
+    At some point in the future these three symbols will become
+    C++11 atomic variables:
+
+    extern std::atomic<std::terminate_handler>  __cxa_terminate_handler;
+    extern std::atomic<std::unexpected_handler> __cxa_unexpected_handler;
+    extern std::atomic<std::new_handler>        __cxa_new_handler;
+
+    This change will not impact their ABI.  But it will allow for a
+    portible performance optimization.
+
+*/
+
 } // extern "C"
 
 #endif  // _CXA_HANDLERS_H





More information about the cfe-commits mailing list