1 // <atomic> compatibility -*- C++ -*-
3 // Copyright (C) 2008, 2009, 2010, 2011
4 // Free Software Foundation, Inc.
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 3, or (at your option)
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // Under Section 7 of GPL version 3, you are granted additional
18 // permissions described in the GCC Runtime Library Exception, version
19 // 3.1, as published by the Free Software Foundation.
21 // You should have received a copy of the GNU General Public License and
22 // a copy of the GCC Runtime Library Exception along with this program;
23 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 // <http://www.gnu.org/licenses/>.
30 // XXX GLIBCXX_ABI Deprecated
37 #if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1)
41 static std::mutex atomic_mutex;
46 std::__atomic_flag_base flag_table[ 1 << LOGSIZE ] =
48 ATOMIC_FLAG_INIT, ATOMIC_FLAG_INIT, ATOMIC_FLAG_INIT, ATOMIC_FLAG_INIT,
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,
53 } // anonymous namespace
55 namespace std _GLIBCXX_VISIBILITY(default)
57 _GLIBCXX_BEGIN_NAMESPACE_VERSION
62 struct atomic_flag : public __atomic_flag_base
65 test_and_set(memory_order) noexcept;
68 clear(memory_order) noexcept;
72 atomic_flag::test_and_set(memory_order) noexcept
74 #if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1)
75 lock_guard<mutex> __lock(get_atomic_mutex());
83 atomic_flag::clear(memory_order) noexcept
85 #if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1)
86 lock_guard<mutex> __lock(get_atomic_mutex());
90 } // namespace __atomic0
92 _GLIBCXX_BEGIN_EXTERN_C
95 atomic_flag_test_and_set_explicit(__atomic_flag_base* __a,
96 memory_order __m) _GLIBCXX_NOTHROW
98 atomic_flag* d = static_cast<atomic_flag*>(__a);
99 return d->test_and_set(__m);
103 atomic_flag_clear_explicit(__atomic_flag_base* __a,
104 memory_order __m) _GLIBCXX_NOTHROW
106 atomic_flag* d = static_cast<atomic_flag*>(__a);
107 return d->clear(__m);
111 __atomic_flag_wait_explicit(__atomic_flag_base* __a,
112 memory_order __x) _GLIBCXX_NOTHROW
114 while (atomic_flag_test_and_set_explicit(__a, __x))
118 _GLIBCXX_CONST __atomic_flag_base*
119 __atomic_flag_for_address(const volatile void* __z) _GLIBCXX_NOTHROW
121 uintptr_t __u = reinterpret_cast<uintptr_t>(__z);
122 __u += (__u >> 2) + (__u << 4);
123 __u += (__u >> 7) + (__u << 5);
124 __u += (__u >> 17) + (__u << 13);
125 if (sizeof(uintptr_t) > 4)
127 __u &= ~((~uintptr_t(0)) << LOGSIZE);
128 return flag_table + __u;
131 _GLIBCXX_END_EXTERN_C
133 _GLIBCXX_END_NAMESPACE_VERSION
137 // XXX GLIBCXX_ABI Deprecated
139 // <atomic> signature changes
141 // The rename syntax for default exported names is
142 // asm (".symver name1,exportedname@GLIBCXX_3.4")
143 // asm (".symver name2,exportedname@@GLIBCXX_3.4.5")
144 // In the future, GLIBCXX_ABI > 6 should remove all uses of
145 // _GLIBCXX_*_SYMVER macros in this file.
147 #if defined(_GLIBCXX_SYMVER_GNU) && defined(PIC) \
148 && defined(_GLIBCXX_HAVE_AS_SYMVER_DIRECTIVE) \
149 && defined(_GLIBCXX_HAVE_SYMVER_SYMBOL_RENAMING_RUNTIME_SUPPORT)
151 #define _GLIBCXX_ASM_SYMVER(cur, old, version) \
152 asm (".symver " #cur "," #old "@@" #version);
154 _GLIBCXX_ASM_SYMVER(_ZNSt9__atomic011atomic_flag5clearESt12memory_order, _ZNVSt9__atomic011atomic_flag5clearESt12memory_order, GLIBCXX_3.4.11)
156 _GLIBCXX_ASM_SYMVER(_ZNSt9__atomic011atomic_flag12test_and_setESt12memory_order, _ZNVSt9__atomic011atomic_flag12test_and_setESt12memory_order, GLIBCXX_3.4.11)