]> git.ipfire.org Git - thirdparty/gcc.git/blame - libgcc/c++-minimal/guard.c
Update copyright years.
[thirdparty/gcc.git] / libgcc / c++-minimal / guard.c
CommitLineData
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
6This file is part of GCC.
7
8GCC is free software; you can redistribute it and/or modify it under
9the terms of the GNU General Public License as published by the Free
10Software Foundation; either version 3, or (at your option) any later
11version.
12
13GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14WARRANTY; without even the implied warranty of MERCHANTABILITY or
15FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16for more details.
17
18Under Section 7 of GPL version 3, you are granted additional
19permissions described in the GCC Runtime Library Exception, version
203.1, as published by the Free Software Foundation.
21
22You should have received a copy of the GNU General Public License and
23a copy of the GCC Runtime Library Exception along with this program;
24see 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
37int
38__cxa_guard_acquire(__guard*);
39
40void
41__cxa_guard_release(__guard*);
42
43void
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
52static inline int
53init_in_progress_flag(__guard* g)
54{ return ((char *)g)[1]; }
55
56static inline void
57set_init_in_progress_flag(__guard* g, int v)
58{ ((char *)g)[1] = v; }
59
60static inline void
61throw_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.
69static int
70acquire(__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
83int __cxa_guard_acquire (__guard *g)
84{
85 return acquire (g);
86}
87
88void __cxa_guard_abort (__guard *g)
89{
90 set_init_in_progress_flag(g, 0);
91}
92
93void __cxa_guard_release (__guard *g)
94{
95 set_init_in_progress_flag(g, 0);
96 _GLIBCXX_GUARD_SET_AND_RELEASE (g);
97}