]>
Commit | Line | Data |
---|---|---|
df4b504c | 1 | // -*- C++ -*- std::terminate, std::unexpected and friends. |
fbd26352 | 2 | // Copyright (C) 1994-2019 Free Software Foundation, Inc. |
df4b504c | 3 | // |
908dad4c | 4 | // This file is part of GCC. |
df4b504c | 5 | // |
908dad4c | 6 | // GCC is free software; you can redistribute it and/or modify |
df4b504c | 7 | // it under the terms of the GNU General Public License as published by |
6bc9506f | 8 | // the Free Software Foundation; either version 3, or (at your option) |
df4b504c | 9 | // any later version. |
10 | // | |
908dad4c | 11 | // GCC is distributed in the hope that it will be useful, |
df4b504c | 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. | |
15 | // | |
6bc9506f | 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. | |
df4b504c | 19 | |
6bc9506f | 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/>. | |
df4b504c | 24 | |
25 | #include "typeinfo" | |
26 | #include "exception" | |
27 | #include <cstdlib> | |
28 | #include "unwind-cxx.h" | |
dee74d2b | 29 | #include <bits/exception_defines.h> |
257b4f53 | 30 | #include <bits/atomic_lockfree_defines.h> |
31 | ||
32 | #if ATOMIC_POINTER_LOCK_FREE < 2 | |
33 | #include <ext/concurrence.h> | |
34 | namespace | |
35 | { | |
36 | __gnu_cxx::__mutex mx; | |
37 | } | |
38 | #endif | |
df4b504c | 39 | |
40 | using namespace __cxxabiv1; | |
41 | ||
df4b504c | 42 | void |
85522548 | 43 | __cxxabiv1::__terminate (std::terminate_handler handler) throw () |
df4b504c | 44 | { |
b66f4546 | 45 | __try |
46 | { | |
47 | handler (); | |
48 | std::abort (); | |
49 | } | |
50 | __catch(...) | |
51 | { std::abort (); } | |
df4b504c | 52 | } |
53 | ||
54 | void | |
85522548 | 55 | std::terminate () throw() |
df4b504c | 56 | { |
a366a1d3 | 57 | __terminate (get_terminate ()); |
df4b504c | 58 | } |
59 | ||
60 | void | |
61 | __cxxabiv1::__unexpected (std::unexpected_handler handler) | |
62 | { | |
63 | handler(); | |
64 | std::terminate (); | |
65 | } | |
66 | ||
67 | void | |
68 | std::unexpected () | |
69 | { | |
a366a1d3 | 70 | __unexpected (get_unexpected ()); |
df4b504c | 71 | } |
72 | ||
73 | std::terminate_handler | |
74 | std::set_terminate (std::terminate_handler func) throw() | |
75 | { | |
a366a1d3 | 76 | std::terminate_handler old; |
257b4f53 | 77 | #if ATOMIC_POINTER_LOCK_FREE > 1 |
a366a1d3 | 78 | __atomic_exchange (&__terminate_handler, &func, &old, __ATOMIC_ACQ_REL); |
257b4f53 | 79 | #else |
80 | __gnu_cxx::__scoped_lock l(mx); | |
81 | old = __terminate_handler; | |
82 | __terminate_handler = func; | |
83 | #endif | |
df4b504c | 84 | return old; |
85 | } | |
86 | ||
a366a1d3 | 87 | std::terminate_handler |
88 | std::get_terminate () noexcept | |
89 | { | |
90 | std::terminate_handler func; | |
257b4f53 | 91 | #if ATOMIC_POINTER_LOCK_FREE > 1 |
a366a1d3 | 92 | __atomic_load (&__terminate_handler, &func, __ATOMIC_ACQUIRE); |
257b4f53 | 93 | #else |
94 | __gnu_cxx::__scoped_lock l(mx); | |
95 | func = __terminate_handler; | |
96 | #endif | |
a366a1d3 | 97 | return func; |
98 | } | |
99 | ||
df4b504c | 100 | std::unexpected_handler |
101 | std::set_unexpected (std::unexpected_handler func) throw() | |
102 | { | |
a366a1d3 | 103 | std::unexpected_handler old; |
257b4f53 | 104 | #if ATOMIC_POINTER_LOCK_FREE > 1 |
a366a1d3 | 105 | __atomic_exchange (&__unexpected_handler, &func, &old, __ATOMIC_ACQ_REL); |
257b4f53 | 106 | #else |
107 | __gnu_cxx::__scoped_lock l(mx); | |
108 | old = __unexpected_handler; | |
109 | __unexpected_handler = func; | |
110 | #endif | |
df4b504c | 111 | return old; |
112 | } | |
a366a1d3 | 113 | |
114 | std::unexpected_handler | |
115 | std::get_unexpected () noexcept | |
116 | { | |
117 | std::unexpected_handler func; | |
257b4f53 | 118 | #if ATOMIC_POINTER_LOCK_FREE > 1 |
a366a1d3 | 119 | __atomic_load (&__unexpected_handler, &func, __ATOMIC_ACQUIRE); |
257b4f53 | 120 | #else |
121 | __gnu_cxx::__scoped_lock l(mx); | |
122 | func = __unexpected_handler; | |
123 | #endif | |
a366a1d3 | 124 | return func; |
125 | } |