N3189 Observers for the three handler functions

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@120712 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/src/exception.cpp b/src/exception.cpp
index 1ab5a19..062114c 100644
--- a/src/exception.cpp
+++ b/src/exception.cpp
@@ -26,9 +26,13 @@
 std::unexpected_handler
 std::set_unexpected(std::unexpected_handler func) throw()
 {
-    std::terminate_handler old = __unexpected_handler;
-    __unexpected_handler = func;
-    return old;
+    return __sync_lock_test_and_set(&__unexpected_handler, func);
+}
+
+std::unexpected_handler
+std::get_unexpected() throw()
+{
+    return __sync_fetch_and_add(&__unexpected_handler, (std::unexpected_handler)0);
 }
 
 void
@@ -42,9 +46,13 @@
 std::terminate_handler
 std::set_terminate(std::terminate_handler func) throw()
 {
-    std::terminate_handler old = __terminate_handler;
-    __terminate_handler = func;
-    return old;
+    return __sync_lock_test_and_set(&__terminate_handler, func);
+}
+
+std::terminate_handler
+std::get_terminate() throw()
+{
+    return __sync_fetch_and_add(&__terminate_handler, (std::terminate_handler)0);
 }
 
 void