]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/src/c++11/compatibility-atomic-c++0x.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / src / c++11 / compatibility-atomic-c++0x.cc
CommitLineData
86951993 1// <atomic> compatibility -*- C++ -*-
d466a7e2 2
8d9254fc 3// Copyright (C) 2008-2020 Free Software Foundation, Inc.
d466a7e2
BK
4//
5// This file is part of the GNU ISO C++ Library. This library is free
6// software; you can redistribute it and/or modify it under the
7// terms of the GNU General Public License as published by the
748086b7 8// Free Software Foundation; either version 3, or (at your option)
d466a7e2
BK
9// any later version.
10
11// This library 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.
15
748086b7
JJ
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.
d466a7e2 19
748086b7
JJ
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/>.
d466a7e2 24
ed0840ba 25#include "gstdint.h"
afd88205 26#include <atomic>
1a6e6753 27#include <mutex>
d466a7e2 28
86951993
AM
29// XXX GLIBCXX_ABI Deprecated
30// gcc-4.7.0
31
ac6d1200 32#ifdef _GLIBCXX_SHARED
0b284728 33
d466a7e2
BK
34#define LOGSIZE 4
35
36namespace
37{
b0c2c850 38#if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1)
99827523
BK
39 std::mutex&
40 get_atomic_mutex()
41 {
42 static std::mutex atomic_mutex;
43 return atomic_mutex;
44 }
50ce8d3d
BK
45#endif
46
afd88205 47 std::__atomic_flag_base flag_table[ 1 << LOGSIZE ] =
d466a7e2
BK
48 {
49 ATOMIC_FLAG_INIT, ATOMIC_FLAG_INIT, ATOMIC_FLAG_INIT, ATOMIC_FLAG_INIT,
50 ATOMIC_FLAG_INIT, ATOMIC_FLAG_INIT, ATOMIC_FLAG_INIT, ATOMIC_FLAG_INIT,
51 ATOMIC_FLAG_INIT, ATOMIC_FLAG_INIT, ATOMIC_FLAG_INIT, ATOMIC_FLAG_INIT,
52 ATOMIC_FLAG_INIT, ATOMIC_FLAG_INIT, ATOMIC_FLAG_INIT, ATOMIC_FLAG_INIT,
53 };
54} // anonymous namespace
55
12ffa228
BK
56namespace std _GLIBCXX_VISIBILITY(default)
57{
58_GLIBCXX_BEGIN_NAMESPACE_VERSION
53dc5044 59
50ce8d3d 60 namespace __atomic0
d466a7e2 61 {
86951993
AM
62
63 struct atomic_flag : public __atomic_flag_base
64 {
65 bool
66 test_and_set(memory_order) noexcept;
f92ab29f 67
86951993
AM
68 void
69 clear(memory_order) noexcept;
70 };
71
50ce8d3d 72 bool
bdc05efb 73 atomic_flag::test_and_set(memory_order) noexcept
50ce8d3d 74 {
b0c2c850 75#if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1)
99827523 76 lock_guard<mutex> __lock(get_atomic_mutex());
d466a7e2 77#endif
50ce8d3d
BK
78 bool result = _M_i;
79 _M_i = true;
80 return result;
81 }
d466a7e2 82
50ce8d3d 83 void
bdc05efb 84 atomic_flag::clear(memory_order) noexcept
50ce8d3d 85 {
b0c2c850 86#if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1)
99827523 87 lock_guard<mutex> __lock(get_atomic_mutex());
d466a7e2 88#endif
50ce8d3d
BK
89 _M_i = false;
90 }
86951993 91 } // namespace __atomic0
94a86be0
BK
92
93 _GLIBCXX_BEGIN_EXTERN_C
94
95 bool
96 atomic_flag_test_and_set_explicit(__atomic_flag_base* __a,
97 memory_order __m) _GLIBCXX_NOTHROW
98 {
99 atomic_flag* d = static_cast<atomic_flag*>(__a);
100 return d->test_and_set(__m);
50ce8d3d 101 }
d466a7e2 102
94a86be0
BK
103 void
104 atomic_flag_clear_explicit(__atomic_flag_base* __a,
105 memory_order __m) _GLIBCXX_NOTHROW
d466a7e2 106 {
94a86be0
BK
107 atomic_flag* d = static_cast<atomic_flag*>(__a);
108 return d->clear(__m);
109 }
d466a7e2 110
94a86be0
BK
111 void
112 __atomic_flag_wait_explicit(__atomic_flag_base* __a,
113 memory_order __x) _GLIBCXX_NOTHROW
114 {
115 while (atomic_flag_test_and_set_explicit(__a, __x))
116 { };
117 }
d466a7e2 118
94a86be0
BK
119 _GLIBCXX_CONST __atomic_flag_base*
120 __atomic_flag_for_address(const volatile void* __z) _GLIBCXX_NOTHROW
121 {
122 uintptr_t __u = reinterpret_cast<uintptr_t>(__z);
123 __u += (__u >> 2) + (__u << 4);
124 __u += (__u >> 7) + (__u << 5);
125 __u += (__u >> 17) + (__u << 13);
126 if (sizeof(uintptr_t) > 4)
127 __u += (__u >> 31);
128 __u &= ~((~uintptr_t(0)) << LOGSIZE);
129 return flag_table + __u;
130 }
d466a7e2 131
94a86be0
BK
132 _GLIBCXX_END_EXTERN_C
133
12ffa228 134_GLIBCXX_END_NAMESPACE_VERSION
86951993 135} // namespace std
afd88205 136
0b284728 137#endif
afd88205
BK
138
139// XXX GLIBCXX_ABI Deprecated
140// gcc-4.5.0
141// <atomic> signature changes
142
143// The rename syntax for default exported names is
144// asm (".symver name1,exportedname@GLIBCXX_3.4")
145// asm (".symver name2,exportedname@@GLIBCXX_3.4.5")
146// In the future, GLIBCXX_ABI > 6 should remove all uses of
147// _GLIBCXX_*_SYMVER macros in this file.
148
ac6d1200 149#if defined(_GLIBCXX_SYMVER_GNU) && defined(_GLIBCXX_SHARED) \
c18dc5cc
RO
150 && defined(_GLIBCXX_HAVE_AS_SYMVER_DIRECTIVE) \
151 && defined(_GLIBCXX_HAVE_SYMVER_SYMBOL_RENAMING_RUNTIME_SUPPORT)
ac2e5c89 152
afd88205
BK
153#define _GLIBCXX_ASM_SYMVER(cur, old, version) \
154 asm (".symver " #cur "," #old "@@" #version);
155
afd88205
BK
156_GLIBCXX_ASM_SYMVER(_ZNSt9__atomic011atomic_flag5clearESt12memory_order, _ZNVSt9__atomic011atomic_flag5clearESt12memory_order, GLIBCXX_3.4.11)
157
158_GLIBCXX_ASM_SYMVER(_ZNSt9__atomic011atomic_flag12test_and_setESt12memory_order, _ZNVSt9__atomic011atomic_flag12test_and_setESt12memory_order, GLIBCXX_3.4.11)
ac2e5c89 159
afd88205 160#endif