1 // -*- C++ -*- std::terminate, std::unexpected and friends.
2 // Copyright (C) 1994-2018 Free Software Foundation, Inc.
4 // This file is part of GCC.
6 // GCC is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 3, or (at your option)
11 // GCC is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
28 #include "unwind-cxx.h"
29 #include <bits/exception_defines.h>
30 #include <bits/atomic_lockfree_defines.h>
32 #if ATOMIC_POINTER_LOCK_FREE < 2
33 #include <ext/concurrence.h>
36 __gnu_cxx::__mutex mx
;
40 using namespace __cxxabiv1
;
43 __cxxabiv1::__terminate (std::terminate_handler handler
) throw ()
55 std::terminate () throw()
57 __terminate (get_terminate ());
61 __cxxabiv1::__unexpected (std::unexpected_handler handler
)
70 __unexpected (get_unexpected ());
73 std::terminate_handler
74 std::set_terminate (std::terminate_handler func
) throw()
76 std::terminate_handler old
;
77 #if ATOMIC_POINTER_LOCK_FREE > 1
78 __atomic_exchange (&__terminate_handler
, &func
, &old
, __ATOMIC_ACQ_REL
);
80 __gnu_cxx::__scoped_lock
l(mx
);
81 old
= __terminate_handler
;
82 __terminate_handler
= func
;
87 std::terminate_handler
88 std::get_terminate () noexcept
90 std::terminate_handler func
;
91 #if ATOMIC_POINTER_LOCK_FREE > 1
92 __atomic_load (&__terminate_handler
, &func
, __ATOMIC_ACQUIRE
);
94 __gnu_cxx::__scoped_lock
l(mx
);
95 func
= __terminate_handler
;
100 std::unexpected_handler
101 std::set_unexpected (std::unexpected_handler func
) throw()
103 std::unexpected_handler old
;
104 #if ATOMIC_POINTER_LOCK_FREE > 1
105 __atomic_exchange (&__unexpected_handler
, &func
, &old
, __ATOMIC_ACQ_REL
);
107 __gnu_cxx::__scoped_lock
l(mx
);
108 old
= __unexpected_handler
;
109 __unexpected_handler
= func
;
114 std::unexpected_handler
115 std::get_unexpected () noexcept
117 std::unexpected_handler func
;
118 #if ATOMIC_POINTER_LOCK_FREE > 1
119 __atomic_load (&__unexpected_handler
, &func
, __ATOMIC_ACQUIRE
);
121 __gnu_cxx::__scoped_lock
l(mx
);
122 func
= __unexpected_handler
;