]>
Commit | Line | Data |
---|---|---|
c0bf7ea1 TS |
1 | /* 'libstdc++-v3/libsupc++/guard.cc' for offload devices, until we have |
2 | libstdc++-v3/libsupc++ proper. | |
3 | ||
a945c346 | 4 | Copyright (C) 2002-2024 Free Software Foundation, Inc. |
c0bf7ea1 TS |
5 | |
6 | This file is part of GCC. | |
7 | ||
8 | GCC is free software; you can redistribute it and/or modify it under | |
9 | the terms of the GNU General Public License as published by the Free | |
10 | Software Foundation; either version 3, or (at your option) any later | |
11 | version. | |
12 | ||
13 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY | |
14 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 | for more details. | |
17 | ||
18 | Under Section 7 of GPL version 3, you are granted additional | |
19 | permissions described in the GCC Runtime Library Exception, version | |
20 | 3.1, as published by the Free Software Foundation. | |
21 | ||
22 | You should have received a copy of the GNU General Public License and | |
23 | a copy of the GCC Runtime Library Exception along with this program; | |
24 | see the files COPYING3 and COPYING.RUNTIME respectively. If not, see | |
25 | <http://www.gnu.org/licenses/>. */ | |
26 | ||
27 | #if defined __AMDGCN__ | |
28 | #elif defined __nvptx__ | |
29 | #else | |
30 | # error not ported | |
31 | #endif | |
32 | ||
33 | #include "../../libstdc++-v3/config/cpu/generic/cxxabi_tweaks.h" | |
34 | ||
35 | /* Copy'n'paste/edit from 'libstdc++-v3/libsupc++/cxxabi.h'. */ | |
36 | ||
37 | int | |
38 | __cxa_guard_acquire(__guard*); | |
39 | ||
40 | void | |
41 | __cxa_guard_release(__guard*); | |
42 | ||
43 | void | |
44 | __cxa_guard_abort(__guard*); | |
45 | ||
46 | /* Copy'n'paste/edit from 'libstdc++-v3/libsupc++/guard.cc'. */ | |
47 | ||
48 | #undef _GLIBCXX_GUARD_TEST_AND_ACQUIRE | |
49 | #undef _GLIBCXX_GUARD_SET_AND_RELEASE | |
50 | #define _GLIBCXX_GUARD_SET_AND_RELEASE(G) _GLIBCXX_GUARD_SET (G) | |
51 | ||
52 | static inline int | |
53 | init_in_progress_flag(__guard* g) | |
54 | { return ((char *)g)[1]; } | |
55 | ||
56 | static inline void | |
57 | set_init_in_progress_flag(__guard* g, int v) | |
58 | { ((char *)g)[1] = v; } | |
59 | ||
60 | static inline void | |
61 | throw_recursive_init_exception(void) | |
62 | { | |
63 | // Use __builtin_trap so we don't require abort(). | |
64 | __builtin_trap(); | |
65 | } | |
66 | ||
67 | // acquire() is a helper function used to acquire guard if thread support is | |
68 | // not compiled in or is compiled in but not enabled at run-time. | |
69 | static int | |
70 | acquire(__guard *g) | |
71 | { | |
72 | // Quit if the object is already initialized. | |
73 | if (_GLIBCXX_GUARD_TEST(g)) | |
74 | return 0; | |
75 | ||
76 | if (init_in_progress_flag(g)) | |
77 | throw_recursive_init_exception(); | |
78 | ||
79 | set_init_in_progress_flag(g, 1); | |
80 | return 1; | |
81 | } | |
82 | ||
83 | int __cxa_guard_acquire (__guard *g) | |
84 | { | |
85 | return acquire (g); | |
86 | } | |
87 | ||
88 | void __cxa_guard_abort (__guard *g) | |
89 | { | |
90 | set_init_in_progress_flag(g, 0); | |
91 | } | |
92 | ||
93 | void __cxa_guard_release (__guard *g) | |
94 | { | |
95 | set_init_in_progress_flag(g, 0); | |
96 | _GLIBCXX_GUARD_SET_AND_RELEASE (g); | |
97 | } |