1 // Support for atomic operations -*- C++ -*-
3 // Copyright (C) 2008, 2009, 2010
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/>.
34 #if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1)
38 static std::mutex atomic_mutex
;
43 std::__atomic_flag_base flag_table
[ 1 << LOGSIZE
] =
45 ATOMIC_FLAG_INIT
, ATOMIC_FLAG_INIT
, ATOMIC_FLAG_INIT
, ATOMIC_FLAG_INIT
,
46 ATOMIC_FLAG_INIT
, ATOMIC_FLAG_INIT
, ATOMIC_FLAG_INIT
, ATOMIC_FLAG_INIT
,
47 ATOMIC_FLAG_INIT
, ATOMIC_FLAG_INIT
, ATOMIC_FLAG_INIT
, ATOMIC_FLAG_INIT
,
48 ATOMIC_FLAG_INIT
, ATOMIC_FLAG_INIT
, ATOMIC_FLAG_INIT
, ATOMIC_FLAG_INIT
,
50 } // anonymous namespace
57 atomic_flag::test_and_set(memory_order
)
59 #if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1)
60 lock_guard
<mutex
> __lock(get_atomic_mutex());
68 atomic_flag::clear(memory_order
)
70 #if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1)
71 lock_guard
<mutex
> __lock(get_atomic_mutex());
80 atomic_flag_test_and_set_explicit(__atomic_flag_base
* __a
,
81 memory_order __m
) throw()
83 atomic_flag
* d
= static_cast<volatile atomic_flag
*>(__a
);
84 return d
->test_and_set(__m
);
88 atomic_flag_clear_explicit(__atomic_flag_base
* __a
,
89 memory_order __m
) throw()
91 atomic_flag
* d
= static_cast<volatile atomic_flag
*>(__a
);
96 __atomic_flag_wait_explicit(__atomic_flag_base
* __a
,
97 memory_order __x
) throw()
99 while (atomic_flag_test_and_set_explicit(__a
, __x
))
104 __atomic_flag_for_address(const void* __z
) throw()
106 uintptr_t __u
= reinterpret_cast<uintptr_t>(__z
);
107 __u
+= (__u
>> 2) + (__u
<< 4);
108 __u
+= (__u
>> 7) + (__u
<< 5);
109 __u
+= (__u
>> 17) + (__u
<< 13);
110 if (sizeof(uintptr_t) > 4)
112 __u
&= ~((~uintptr_t(0)) << LOGSIZE
);
113 return flag_table
+ __u
;
119 // XXX GLIBCXX_ABI Deprecated
121 // <atomic> signature changes
123 // The rename syntax for default exported names is
124 // asm (".symver name1,exportedname@GLIBCXX_3.4")
125 // asm (".symver name2,exportedname@@GLIBCXX_3.4.5")
126 // In the future, GLIBCXX_ABI > 6 should remove all uses of
127 // _GLIBCXX_*_SYMVER macros in this file.
129 #if defined(_GLIBCXX_SYMVER_GNU) && defined(PIC) \
130 && defined(_GLIBCXX_HAVE_AS_SYMVER_DIRECTIVE) \
131 && defined(_GLIBCXX_HAVE_SYMVER_SYMBOL_RENAMING_RUNTIME_SUPPORT)
133 #define _GLIBCXX_ASM_SYMVER(cur, old, version) \
134 asm (".symver " #cur "," #old "@@" #version);
136 _GLIBCXX_ASM_SYMVER(_ZNSt9__atomic011atomic_flag5clearESt12memory_order
, _ZNVSt9__atomic011atomic_flag5clearESt12memory_order
, GLIBCXX_3
.4
.11)
138 _GLIBCXX_ASM_SYMVER(_ZNSt9__atomic011atomic_flag12test_and_setESt12memory_order
, _ZNVSt9__atomic011atomic_flag12test_and_setESt12memory_order
, GLIBCXX_3
.4
.11)