summaryrefslogtreecommitdiff
path: root/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
commit4cfb63f07516ceff10be81c7dfac6c18122df782 (patch)
treee766292fd63635abae6587f793bb0189e0497523 /src/cxa_handlers.cpp
parent0f80bb79c0181c706cf6acce44f854e96ecaf755 (diff)
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.
git-svn-id: https://llvm.org/svn/llvm-project/libcxxabi/trunk@153041 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'src/cxa_handlers.cpp')
-rw-r--r--src/cxa_handlers.cpp19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/cxa_handlers.cpp b/src/cxa_handlers.cpp
index 3150c0a..100fc50 100644
--- a/src/cxa_handlers.cpp
+++ b/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