summaryrefslogtreecommitdiffstats
path: root/libcxxabi/src/cxa_handlers.cpp
diff options
context:
space:
mode:
authorHoward Hinnant <hhinnant@apple.com>2012-03-19 16:56:51 +0000
committerHoward Hinnant <hhinnant@apple.com>2012-03-19 16:56:51 +0000
commite59dbd7b826b848edbc2497f119d72044ec2a3cf (patch)
treeb1288ab3b260a8c7f739835134a755202cc80a00 /libcxxabi/src/cxa_handlers.cpp
parentc58dc9fcd2bca6534613a0e30971a3e2acbe231b (diff)
downloadbcm5719-llvm-e59dbd7b826b848edbc2497f119d72044ec2a3cf.tar.gz
bcm5719-llvm-e59dbd7b826b848edbc2497f119d72044ec2a3cf.zip
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.
llvm-svn: 153041
Diffstat (limited to 'libcxxabi/src/cxa_handlers.cpp')
-rw-r--r--libcxxabi/src/cxa_handlers.cpp19
1 files changed, 16 insertions, 3 deletions
diff --git a/libcxxabi/src/cxa_handlers.cpp b/libcxxabi/src/cxa_handlers.cpp
index 3150c0a6de0..100fc50c7bc 100644
--- a/libcxxabi/src/cxa_handlers.cpp
+++ b/libcxxabi/src/cxa_handlers.cpp
@@ -25,7 +25,10 @@ namespace std
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 @@ unexpected()
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 @@ terminate() _NOEXCEPT
}
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
OpenPOWER on IntegriCloud