annotate libstdc++-v3/libsupc++/eh_terminate.cc @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 // -*- C++ -*- std::terminate, std::unexpected and friends.
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2 // Copyright (C) 1994-2020 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
3 //
kono
parents:
diff changeset
4 // This file is part of GCC.
kono
parents:
diff changeset
5 //
kono
parents:
diff changeset
6 // GCC is free software; you can redistribute it and/or modify
kono
parents:
diff changeset
7 // it under the terms of the GNU General Public License as published by
kono
parents:
diff changeset
8 // the Free Software Foundation; either version 3, or (at your option)
kono
parents:
diff changeset
9 // any later version.
kono
parents:
diff changeset
10 //
kono
parents:
diff changeset
11 // GCC is distributed in the hope that it will be useful,
kono
parents:
diff changeset
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
kono
parents:
diff changeset
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
kono
parents:
diff changeset
14 // GNU General Public License for more details.
kono
parents:
diff changeset
15 //
kono
parents:
diff changeset
16 // Under Section 7 of GPL version 3, you are granted additional
kono
parents:
diff changeset
17 // permissions described in the GCC Runtime Library Exception, version
kono
parents:
diff changeset
18 // 3.1, as published by the Free Software Foundation.
kono
parents:
diff changeset
19
kono
parents:
diff changeset
20 // You should have received a copy of the GNU General Public License and
kono
parents:
diff changeset
21 // a copy of the GCC Runtime Library Exception along with this program;
kono
parents:
diff changeset
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
kono
parents:
diff changeset
23 // <http://www.gnu.org/licenses/>.
kono
parents:
diff changeset
24
kono
parents:
diff changeset
25 #include "typeinfo"
kono
parents:
diff changeset
26 #include "exception"
kono
parents:
diff changeset
27 #include <cstdlib>
kono
parents:
diff changeset
28 #include "unwind-cxx.h"
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
29 #include "eh_term_handler.h"
111
kono
parents:
diff changeset
30 #include <bits/exception_defines.h>
kono
parents:
diff changeset
31 #include <bits/atomic_lockfree_defines.h>
kono
parents:
diff changeset
32
kono
parents:
diff changeset
33 #if ATOMIC_POINTER_LOCK_FREE < 2
kono
parents:
diff changeset
34 #include <ext/concurrence.h>
kono
parents:
diff changeset
35 namespace
kono
parents:
diff changeset
36 {
kono
parents:
diff changeset
37 __gnu_cxx::__mutex mx;
kono
parents:
diff changeset
38 }
kono
parents:
diff changeset
39 #endif
kono
parents:
diff changeset
40
kono
parents:
diff changeset
41 using namespace __cxxabiv1;
kono
parents:
diff changeset
42
kono
parents:
diff changeset
43 void
kono
parents:
diff changeset
44 __cxxabiv1::__terminate (std::terminate_handler handler) throw ()
kono
parents:
diff changeset
45 {
kono
parents:
diff changeset
46 __try
kono
parents:
diff changeset
47 {
kono
parents:
diff changeset
48 handler ();
kono
parents:
diff changeset
49 std::abort ();
kono
parents:
diff changeset
50 }
kono
parents:
diff changeset
51 __catch(...)
kono
parents:
diff changeset
52 { std::abort (); }
kono
parents:
diff changeset
53 }
kono
parents:
diff changeset
54
kono
parents:
diff changeset
55 void
kono
parents:
diff changeset
56 std::terminate () throw()
kono
parents:
diff changeset
57 {
kono
parents:
diff changeset
58 __terminate (get_terminate ());
kono
parents:
diff changeset
59 }
kono
parents:
diff changeset
60
kono
parents:
diff changeset
61 void
kono
parents:
diff changeset
62 __cxxabiv1::__unexpected (std::unexpected_handler handler)
kono
parents:
diff changeset
63 {
kono
parents:
diff changeset
64 handler();
kono
parents:
diff changeset
65 std::terminate ();
kono
parents:
diff changeset
66 }
kono
parents:
diff changeset
67
kono
parents:
diff changeset
68 void
kono
parents:
diff changeset
69 std::unexpected ()
kono
parents:
diff changeset
70 {
kono
parents:
diff changeset
71 __unexpected (get_unexpected ());
kono
parents:
diff changeset
72 }
kono
parents:
diff changeset
73
kono
parents:
diff changeset
74 std::terminate_handler
kono
parents:
diff changeset
75 std::set_terminate (std::terminate_handler func) throw()
kono
parents:
diff changeset
76 {
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
77 if (!func)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
78 func = _GLIBCXX_DEFAULT_TERM_HANDLER;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
79
111
kono
parents:
diff changeset
80 std::terminate_handler old;
kono
parents:
diff changeset
81 #if ATOMIC_POINTER_LOCK_FREE > 1
kono
parents:
diff changeset
82 __atomic_exchange (&__terminate_handler, &func, &old, __ATOMIC_ACQ_REL);
kono
parents:
diff changeset
83 #else
kono
parents:
diff changeset
84 __gnu_cxx::__scoped_lock l(mx);
kono
parents:
diff changeset
85 old = __terminate_handler;
kono
parents:
diff changeset
86 __terminate_handler = func;
kono
parents:
diff changeset
87 #endif
kono
parents:
diff changeset
88 return old;
kono
parents:
diff changeset
89 }
kono
parents:
diff changeset
90
kono
parents:
diff changeset
91 std::terminate_handler
kono
parents:
diff changeset
92 std::get_terminate () noexcept
kono
parents:
diff changeset
93 {
kono
parents:
diff changeset
94 std::terminate_handler func;
kono
parents:
diff changeset
95 #if ATOMIC_POINTER_LOCK_FREE > 1
kono
parents:
diff changeset
96 __atomic_load (&__terminate_handler, &func, __ATOMIC_ACQUIRE);
kono
parents:
diff changeset
97 #else
kono
parents:
diff changeset
98 __gnu_cxx::__scoped_lock l(mx);
kono
parents:
diff changeset
99 func = __terminate_handler;
kono
parents:
diff changeset
100 #endif
kono
parents:
diff changeset
101 return func;
kono
parents:
diff changeset
102 }
kono
parents:
diff changeset
103
kono
parents:
diff changeset
104 std::unexpected_handler
kono
parents:
diff changeset
105 std::set_unexpected (std::unexpected_handler func) throw()
kono
parents:
diff changeset
106 {
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
107 if (!func)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
108 func = std::terminate;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
109
111
kono
parents:
diff changeset
110 std::unexpected_handler old;
kono
parents:
diff changeset
111 #if ATOMIC_POINTER_LOCK_FREE > 1
kono
parents:
diff changeset
112 __atomic_exchange (&__unexpected_handler, &func, &old, __ATOMIC_ACQ_REL);
kono
parents:
diff changeset
113 #else
kono
parents:
diff changeset
114 __gnu_cxx::__scoped_lock l(mx);
kono
parents:
diff changeset
115 old = __unexpected_handler;
kono
parents:
diff changeset
116 __unexpected_handler = func;
kono
parents:
diff changeset
117 #endif
kono
parents:
diff changeset
118 return old;
kono
parents:
diff changeset
119 }
kono
parents:
diff changeset
120
kono
parents:
diff changeset
121 std::unexpected_handler
kono
parents:
diff changeset
122 std::get_unexpected () noexcept
kono
parents:
diff changeset
123 {
kono
parents:
diff changeset
124 std::unexpected_handler func;
kono
parents:
diff changeset
125 #if ATOMIC_POINTER_LOCK_FREE > 1
kono
parents:
diff changeset
126 __atomic_load (&__unexpected_handler, &func, __ATOMIC_ACQUIRE);
kono
parents:
diff changeset
127 #else
kono
parents:
diff changeset
128 __gnu_cxx::__scoped_lock l(mx);
kono
parents:
diff changeset
129 func = __unexpected_handler;
kono
parents:
diff changeset
130 #endif
kono
parents:
diff changeset
131 return func;
kono
parents:
diff changeset
132 }