| 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #ifndef _LIBCPP___ATOMIC_ATOMIC_H |
| 10 | #define _LIBCPP___ATOMIC_ATOMIC_H |
| 11 | |
| 12 | #include <__atomic/atomic_sync.h> |
| 13 | #include <__atomic/atomic_waitable_traits.h> |
| 14 | #include <__atomic/check_memory_order.h> |
| 15 | #include <__atomic/floating_point_helper.h> |
| 16 | #include <__atomic/is_always_lock_free.h> |
| 17 | #include <__atomic/memory_order.h> |
| 18 | #include <__atomic/support.h> |
| 19 | #include <__concepts/arithmetic.h> |
| 20 | #include <__concepts/same_as.h> |
| 21 | #include <__config> |
| 22 | #include <__cstddef/ptrdiff_t.h> |
| 23 | #include <__memory/addressof.h> |
| 24 | #include <__type_traits/enable_if.h> |
| 25 | #include <__type_traits/is_constructible.h> |
| 26 | #include <__type_traits/is_floating_point.h> |
| 27 | #include <__type_traits/is_function.h> |
| 28 | #include <__type_traits/is_integral.h> |
| 29 | #include <__type_traits/is_nothrow_constructible.h> |
| 30 | #include <__type_traits/is_pointer.h> |
| 31 | #include <__type_traits/is_same.h> |
| 32 | #include <__type_traits/is_trivially_copyable.h> |
| 33 | #include <__type_traits/remove_pointer.h> |
| 34 | #include <__utility/forward.h> |
| 35 | #include <cstring> |
| 36 | |
| 37 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 38 | # pragma GCC system_header |
| 39 | #endif |
| 40 | |
| 41 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 42 | |
| 43 | template <class _Tp, bool = is_integral<_Tp>::value && !is_same<_Tp, bool>::value> |
| 44 | struct __atomic_base // false |
| 45 | { |
| 46 | mutable __cxx_atomic_impl<_Tp> __a_; |
| 47 | |
| 48 | using value_type = _Tp; |
| 49 | |
| 50 | #if _LIBCPP_STD_VER >= 17 |
| 51 | static constexpr bool is_always_lock_free = __libcpp_is_always_lock_free<__cxx_atomic_impl<_Tp> >::__value; |
| 52 | #endif |
| 53 | |
| 54 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool is_lock_free() const volatile _NOEXCEPT { |
| 55 | return __cxx_atomic_is_lock_free(sizeof(__cxx_atomic_impl<_Tp>)); |
| 56 | } |
| 57 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool is_lock_free() const _NOEXCEPT { |
| 58 | return static_cast<__atomic_base const volatile*>(this)->is_lock_free(); |
| 59 | } |
| 60 | _LIBCPP_HIDE_FROM_ABI void store(_Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT |
| 61 | _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) { |
| 62 | std::__cxx_atomic_store(std::addressof(__a_), __d, __m); |
| 63 | } |
| 64 | _LIBCPP_HIDE_FROM_ABI void store(_Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT |
| 65 | _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) { |
| 66 | std::__cxx_atomic_store(std::addressof(__a_), __d, __m); |
| 67 | } |
| 68 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _Tp load(memory_order __m = memory_order_seq_cst) const volatile _NOEXCEPT |
| 69 | _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) { |
| 70 | return std::__cxx_atomic_load(std::addressof(__a_), __m); |
| 71 | } |
| 72 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _Tp load(memory_order __m = memory_order_seq_cst) const _NOEXCEPT |
| 73 | _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) { |
| 74 | return std::__cxx_atomic_load(std::addressof(__a_), __m); |
| 75 | } |
| 76 | _LIBCPP_HIDE_FROM_ABI operator _Tp() const volatile _NOEXCEPT { return load(); } |
| 77 | _LIBCPP_HIDE_FROM_ABI operator _Tp() const _NOEXCEPT { return load(); } |
| 78 | _LIBCPP_HIDE_FROM_ABI _Tp exchange(_Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT { |
| 79 | return std::__cxx_atomic_exchange(std::addressof(__a_), __d, __m); |
| 80 | } |
| 81 | _LIBCPP_HIDE_FROM_ABI _Tp exchange(_Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT { |
| 82 | return std::__cxx_atomic_exchange(std::addressof(__a_), __d, __m); |
| 83 | } |
| 84 | _LIBCPP_HIDE_FROM_ABI bool |
| 85 | compare_exchange_weak(_Tp& __e, _Tp __d, memory_order __s, memory_order __f) volatile _NOEXCEPT |
| 86 | _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) { |
| 87 | return std::__cxx_atomic_compare_exchange_weak(std::addressof(__a_), std::addressof(__e), __d, __s, __f); |
| 88 | } |
| 89 | _LIBCPP_HIDE_FROM_ABI bool compare_exchange_weak(_Tp& __e, _Tp __d, memory_order __s, memory_order __f) _NOEXCEPT |
| 90 | _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) { |
| 91 | return std::__cxx_atomic_compare_exchange_weak(std::addressof(__a_), std::addressof(__e), __d, __s, __f); |
| 92 | } |
| 93 | _LIBCPP_HIDE_FROM_ABI bool |
| 94 | compare_exchange_strong(_Tp& __e, _Tp __d, memory_order __s, memory_order __f) volatile _NOEXCEPT |
| 95 | _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) { |
| 96 | return std::__cxx_atomic_compare_exchange_strong(std::addressof(__a_), std::addressof(__e), __d, __s, __f); |
| 97 | } |
| 98 | _LIBCPP_HIDE_FROM_ABI bool compare_exchange_strong(_Tp& __e, _Tp __d, memory_order __s, memory_order __f) _NOEXCEPT |
| 99 | _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) { |
| 100 | return std::__cxx_atomic_compare_exchange_strong(std::addressof(__a_), std::addressof(__e), __d, __s, __f); |
| 101 | } |
| 102 | _LIBCPP_HIDE_FROM_ABI bool |
| 103 | compare_exchange_weak(_Tp& __e, _Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT { |
| 104 | return std::__cxx_atomic_compare_exchange_weak(std::addressof(__a_), std::addressof(__e), __d, __m, __m); |
| 105 | } |
| 106 | _LIBCPP_HIDE_FROM_ABI bool |
| 107 | compare_exchange_weak(_Tp& __e, _Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT { |
| 108 | return std::__cxx_atomic_compare_exchange_weak(std::addressof(__a_), std::addressof(__e), __d, __m, __m); |
| 109 | } |
| 110 | _LIBCPP_HIDE_FROM_ABI bool |
| 111 | compare_exchange_strong(_Tp& __e, _Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT { |
| 112 | return std::__cxx_atomic_compare_exchange_strong(std::addressof(__a_), std::addressof(__e), __d, __m, __m); |
| 113 | } |
| 114 | _LIBCPP_HIDE_FROM_ABI bool |
| 115 | compare_exchange_strong(_Tp& __e, _Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT { |
| 116 | return std::__cxx_atomic_compare_exchange_strong(std::addressof(__a_), std::addressof(__e), __d, __m, __m); |
| 117 | } |
| 118 | |
| 119 | #if _LIBCPP_STD_VER >= 20 |
| 120 | _LIBCPP_HIDE_FROM_ABI void wait(_Tp __v, memory_order __m = memory_order_seq_cst) const volatile noexcept { |
| 121 | std::__atomic_wait(*this, __v, __m); |
| 122 | } |
| 123 | _LIBCPP_HIDE_FROM_ABI void wait(_Tp __v, memory_order __m = memory_order_seq_cst) const noexcept { |
| 124 | std::__atomic_wait(*this, __v, __m); |
| 125 | } |
| 126 | _LIBCPP_HIDE_FROM_ABI void notify_one() volatile noexcept { std::__atomic_notify_one(*this); } |
| 127 | _LIBCPP_HIDE_FROM_ABI void notify_one() noexcept { std::__atomic_notify_one(*this); } |
| 128 | _LIBCPP_HIDE_FROM_ABI void notify_all() volatile noexcept { std::__atomic_notify_all(*this); } |
| 129 | _LIBCPP_HIDE_FROM_ABI void notify_all() noexcept { std::__atomic_notify_all(*this); } |
| 130 | #endif // _LIBCPP_STD_VER >= 20 |
| 131 | |
| 132 | #if _LIBCPP_STD_VER >= 20 |
| 133 | _LIBCPP_HIDE_FROM_ABI constexpr __atomic_base() noexcept(is_nothrow_default_constructible_v<_Tp>) : __a_(_Tp()) {} |
| 134 | #else |
| 135 | _LIBCPP_HIDE_FROM_ABI __atomic_base() _NOEXCEPT = default; |
| 136 | #endif |
| 137 | |
| 138 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __atomic_base(_Tp __d) _NOEXCEPT : __a_(__d) {} |
| 139 | |
| 140 | __atomic_base(const __atomic_base&) = delete; |
| 141 | }; |
| 142 | |
| 143 | // atomic<Integral> |
| 144 | |
| 145 | template <class _Tp> |
| 146 | struct __atomic_base<_Tp, true> : public __atomic_base<_Tp, false> { |
| 147 | using __base _LIBCPP_NODEBUG = __atomic_base<_Tp, false>; |
| 148 | |
| 149 | using difference_type = typename __base::value_type; |
| 150 | |
| 151 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __atomic_base() _NOEXCEPT = default; |
| 152 | |
| 153 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __atomic_base(_Tp __d) _NOEXCEPT : __base(__d) {} |
| 154 | |
| 155 | _LIBCPP_HIDE_FROM_ABI _Tp fetch_add(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT { |
| 156 | return std::__cxx_atomic_fetch_add(std::addressof(this->__a_), __op, __m); |
| 157 | } |
| 158 | _LIBCPP_HIDE_FROM_ABI _Tp fetch_add(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT { |
| 159 | return std::__cxx_atomic_fetch_add(std::addressof(this->__a_), __op, __m); |
| 160 | } |
| 161 | _LIBCPP_HIDE_FROM_ABI _Tp fetch_sub(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT { |
| 162 | return std::__cxx_atomic_fetch_sub(std::addressof(this->__a_), __op, __m); |
| 163 | } |
| 164 | _LIBCPP_HIDE_FROM_ABI _Tp fetch_sub(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT { |
| 165 | return std::__cxx_atomic_fetch_sub(std::addressof(this->__a_), __op, __m); |
| 166 | } |
| 167 | _LIBCPP_HIDE_FROM_ABI _Tp fetch_and(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT { |
| 168 | return std::__cxx_atomic_fetch_and(std::addressof(this->__a_), __op, __m); |
| 169 | } |
| 170 | _LIBCPP_HIDE_FROM_ABI _Tp fetch_and(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT { |
| 171 | return std::__cxx_atomic_fetch_and(std::addressof(this->__a_), __op, __m); |
| 172 | } |
| 173 | _LIBCPP_HIDE_FROM_ABI _Tp fetch_or(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT { |
| 174 | return std::__cxx_atomic_fetch_or(std::addressof(this->__a_), __op, __m); |
| 175 | } |
| 176 | _LIBCPP_HIDE_FROM_ABI _Tp fetch_or(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT { |
| 177 | return std::__cxx_atomic_fetch_or(std::addressof(this->__a_), __op, __m); |
| 178 | } |
| 179 | _LIBCPP_HIDE_FROM_ABI _Tp fetch_xor(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT { |
| 180 | return std::__cxx_atomic_fetch_xor(std::addressof(this->__a_), __op, __m); |
| 181 | } |
| 182 | _LIBCPP_HIDE_FROM_ABI _Tp fetch_xor(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT { |
| 183 | return std::__cxx_atomic_fetch_xor(std::addressof(this->__a_), __op, __m); |
| 184 | } |
| 185 | #if _LIBCPP_STD_VER >= 26 |
| 186 | _LIBCPP_HIDE_FROM_ABI _Tp fetch_max(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT { |
| 187 | return std::__cxx_atomic_fetch_max(std::addressof(this->__a_), __op, __m); |
| 188 | } |
| 189 | _LIBCPP_HIDE_FROM_ABI _Tp fetch_max(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT { |
| 190 | return std::__cxx_atomic_fetch_max(std::addressof(this->__a_), __op, __m); |
| 191 | } |
| 192 | _LIBCPP_HIDE_FROM_ABI _Tp fetch_min(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT { |
| 193 | return std::__cxx_atomic_fetch_min(std::addressof(this->__a_), __op, __m); |
| 194 | } |
| 195 | _LIBCPP_HIDE_FROM_ABI _Tp fetch_min(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT { |
| 196 | return std::__cxx_atomic_fetch_min(std::addressof(this->__a_), __op, __m); |
| 197 | } |
| 198 | #endif |
| 199 | |
| 200 | _LIBCPP_HIDE_FROM_ABI _Tp operator++(int) volatile _NOEXCEPT { return fetch_add(_Tp(1)); } |
| 201 | _LIBCPP_HIDE_FROM_ABI _Tp operator++(int) _NOEXCEPT { return fetch_add(_Tp(1)); } |
| 202 | _LIBCPP_HIDE_FROM_ABI _Tp operator--(int) volatile _NOEXCEPT { return fetch_sub(_Tp(1)); } |
| 203 | _LIBCPP_HIDE_FROM_ABI _Tp operator--(int) _NOEXCEPT { return fetch_sub(_Tp(1)); } |
| 204 | _LIBCPP_HIDE_FROM_ABI _Tp operator++() volatile _NOEXCEPT { return fetch_add(_Tp(1)) + _Tp(1); } |
| 205 | _LIBCPP_HIDE_FROM_ABI _Tp operator++() _NOEXCEPT { return fetch_add(_Tp(1)) + _Tp(1); } |
| 206 | _LIBCPP_HIDE_FROM_ABI _Tp operator--() volatile _NOEXCEPT { return fetch_sub(_Tp(1)) - _Tp(1); } |
| 207 | _LIBCPP_HIDE_FROM_ABI _Tp operator--() _NOEXCEPT { return fetch_sub(_Tp(1)) - _Tp(1); } |
| 208 | _LIBCPP_HIDE_FROM_ABI _Tp operator+=(_Tp __op) volatile _NOEXCEPT { return fetch_add(__op) + __op; } |
| 209 | _LIBCPP_HIDE_FROM_ABI _Tp operator+=(_Tp __op) _NOEXCEPT { return fetch_add(__op) + __op; } |
| 210 | _LIBCPP_HIDE_FROM_ABI _Tp operator-=(_Tp __op) volatile _NOEXCEPT { return fetch_sub(__op) - __op; } |
| 211 | _LIBCPP_HIDE_FROM_ABI _Tp operator-=(_Tp __op) _NOEXCEPT { return fetch_sub(__op) - __op; } |
| 212 | _LIBCPP_HIDE_FROM_ABI _Tp operator&=(_Tp __op) volatile _NOEXCEPT { return fetch_and(__op) & __op; } |
| 213 | _LIBCPP_HIDE_FROM_ABI _Tp operator&=(_Tp __op) _NOEXCEPT { return fetch_and(__op) & __op; } |
| 214 | _LIBCPP_HIDE_FROM_ABI _Tp operator|=(_Tp __op) volatile _NOEXCEPT { return fetch_or(__op) | __op; } |
| 215 | _LIBCPP_HIDE_FROM_ABI _Tp operator|=(_Tp __op) _NOEXCEPT { return fetch_or(__op) | __op; } |
| 216 | _LIBCPP_HIDE_FROM_ABI _Tp operator^=(_Tp __op) volatile _NOEXCEPT { return fetch_xor(__op) ^ __op; } |
| 217 | _LIBCPP_HIDE_FROM_ABI _Tp operator^=(_Tp __op) _NOEXCEPT { return fetch_xor(__op) ^ __op; } |
| 218 | }; |
| 219 | |
| 220 | #if _LIBCPP_STD_VER >= 20 |
| 221 | // Here we need _IsIntegral because the default template argument is not enough |
| 222 | // e.g __atomic_base<int> is __atomic_base<int, true>, which inherits from |
| 223 | // __atomic_base<int, false> and the caller of the wait function is |
| 224 | // __atomic_base<int, false>. So specializing __atomic_base<_Tp> does not work |
| 225 | template <class _Tp, bool _IsIntegral> |
| 226 | struct __atomic_waitable_traits<__atomic_base<_Tp, _IsIntegral> > { |
| 227 | using __value_type _LIBCPP_NODEBUG = _Tp; |
| 228 | |
| 229 | static _LIBCPP_HIDE_FROM_ABI _Tp __atomic_load(const __atomic_base<_Tp, _IsIntegral>& __a, memory_order __order) { |
| 230 | return __a.load(__order); |
| 231 | } |
| 232 | |
| 233 | static _LIBCPP_HIDE_FROM_ABI _Tp |
| 234 | __atomic_load(const volatile __atomic_base<_Tp, _IsIntegral>& __this, memory_order __order) { |
| 235 | return __this.load(__order); |
| 236 | } |
| 237 | |
| 238 | static _LIBCPP_HIDE_FROM_ABI const __cxx_atomic_impl<_Tp>* |
| 239 | __atomic_contention_address(const __atomic_base<_Tp, _IsIntegral>& __a) { |
| 240 | return std::addressof(__a.__a_); |
| 241 | } |
| 242 | |
| 243 | static _LIBCPP_HIDE_FROM_ABI const volatile __cxx_atomic_impl<_Tp>* |
| 244 | __atomic_contention_address(const volatile __atomic_base<_Tp, _IsIntegral>& __this) { |
| 245 | return std::addressof(__this.__a_); |
| 246 | } |
| 247 | }; |
| 248 | |
| 249 | #endif // _LIBCPP_STD_VER >= 20 |
| 250 | |
| 251 | template <typename _Tp> |
| 252 | struct __check_atomic_mandates { |
| 253 | using type _LIBCPP_NODEBUG = _Tp; |
| 254 | static_assert(is_trivially_copyable<_Tp>::value, "std::atomic<T> requires that 'T' be a trivially copyable type" ); |
| 255 | }; |
| 256 | |
| 257 | template <class _Tp> |
| 258 | struct atomic : public __atomic_base<typename __check_atomic_mandates<_Tp>::type> { |
| 259 | using __base _LIBCPP_NODEBUG = __atomic_base<_Tp>; |
| 260 | |
| 261 | #if _LIBCPP_STD_VER >= 20 |
| 262 | _LIBCPP_HIDE_FROM_ABI atomic() |
| 263 | requires is_default_constructible_v<_Tp> |
| 264 | = default; |
| 265 | #else |
| 266 | _LIBCPP_HIDE_FROM_ABI atomic() _NOEXCEPT = default; |
| 267 | #endif |
| 268 | |
| 269 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR atomic(_Tp __d) _NOEXCEPT : __base(__d) {} |
| 270 | |
| 271 | _LIBCPP_HIDE_FROM_ABI _Tp operator=(_Tp __d) volatile _NOEXCEPT { |
| 272 | __base::store(__d); |
| 273 | return __d; |
| 274 | } |
| 275 | _LIBCPP_HIDE_FROM_ABI _Tp operator=(_Tp __d) _NOEXCEPT { |
| 276 | __base::store(__d); |
| 277 | return __d; |
| 278 | } |
| 279 | |
| 280 | atomic& operator=(const atomic&) = delete; |
| 281 | atomic& operator=(const atomic&) volatile = delete; |
| 282 | }; |
| 283 | |
| 284 | // atomic<T*> |
| 285 | |
| 286 | template <class _Tp> |
| 287 | struct atomic<_Tp*> : public __atomic_base<_Tp*> { |
| 288 | using __base _LIBCPP_NODEBUG = __atomic_base<_Tp*>; |
| 289 | |
| 290 | using difference_type = ptrdiff_t; |
| 291 | |
| 292 | _LIBCPP_HIDE_FROM_ABI atomic() _NOEXCEPT = default; |
| 293 | |
| 294 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR atomic(_Tp* __d) _NOEXCEPT : __base(__d) {} |
| 295 | |
| 296 | _LIBCPP_HIDE_FROM_ABI _Tp* operator=(_Tp* __d) volatile _NOEXCEPT { |
| 297 | __base::store(__d); |
| 298 | return __d; |
| 299 | } |
| 300 | _LIBCPP_HIDE_FROM_ABI _Tp* operator=(_Tp* __d) _NOEXCEPT { |
| 301 | __base::store(__d); |
| 302 | return __d; |
| 303 | } |
| 304 | |
| 305 | _LIBCPP_HIDE_FROM_ABI _Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT { |
| 306 | // __atomic_fetch_add accepts function pointers, guard against them. |
| 307 | static_assert(!is_function<__remove_pointer_t<_Tp> >::value, "Pointer to function isn't allowed" ); |
| 308 | return std::__cxx_atomic_fetch_add(std::addressof(this->__a_), __op, __m); |
| 309 | } |
| 310 | |
| 311 | _LIBCPP_HIDE_FROM_ABI _Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT { |
| 312 | // __atomic_fetch_add accepts function pointers, guard against them. |
| 313 | static_assert(!is_function<__remove_pointer_t<_Tp> >::value, "Pointer to function isn't allowed" ); |
| 314 | return std::__cxx_atomic_fetch_add(std::addressof(this->__a_), __op, __m); |
| 315 | } |
| 316 | |
| 317 | _LIBCPP_HIDE_FROM_ABI _Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT { |
| 318 | // __atomic_fetch_sub accepts function pointers, guard against them. |
| 319 | static_assert(!is_function<__remove_pointer_t<_Tp> >::value, "Pointer to function isn't allowed" ); |
| 320 | return std::__cxx_atomic_fetch_sub(std::addressof(this->__a_), __op, __m); |
| 321 | } |
| 322 | |
| 323 | _LIBCPP_HIDE_FROM_ABI _Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT { |
| 324 | // __atomic_fetch_sub accepts function pointers, guard against them. |
| 325 | static_assert(!is_function<__remove_pointer_t<_Tp> >::value, "Pointer to function isn't allowed" ); |
| 326 | return std::__cxx_atomic_fetch_sub(std::addressof(this->__a_), __op, __m); |
| 327 | } |
| 328 | |
| 329 | #if _LIBCPP_STD_VER >= 26 |
| 330 | _LIBCPP_HIDE_FROM_ABI _Tp* fetch_max(_Tp* __op, memory_order __m = memory_order_seq_cst) volatile noexcept { |
| 331 | static_assert(!is_function<__remove_pointer_t<_Tp> >::value, "Pointer to function isn't allowed" ); |
| 332 | return std::__cxx_atomic_fetch_max(std::addressof(this->__a_), __op, __m); |
| 333 | } |
| 334 | |
| 335 | _LIBCPP_HIDE_FROM_ABI _Tp* fetch_max(_Tp* __op, memory_order __m = memory_order_seq_cst) noexcept { |
| 336 | static_assert(!is_function<__remove_pointer_t<_Tp> >::value, "Pointer to function isn't allowed" ); |
| 337 | return std::__cxx_atomic_fetch_max(std::addressof(this->__a_), __op, __m); |
| 338 | } |
| 339 | |
| 340 | _LIBCPP_HIDE_FROM_ABI _Tp* fetch_min(_Tp* __op, memory_order __m = memory_order_seq_cst) volatile noexcept { |
| 341 | static_assert(!is_function<__remove_pointer_t<_Tp> >::value, "Pointer to function isn't allowed" ); |
| 342 | return std::__cxx_atomic_fetch_min(std::addressof(this->__a_), __op, __m); |
| 343 | } |
| 344 | |
| 345 | _LIBCPP_HIDE_FROM_ABI _Tp* fetch_min(_Tp* __op, memory_order __m = memory_order_seq_cst) noexcept { |
| 346 | static_assert(!is_function<__remove_pointer_t<_Tp> >::value, "Pointer to function isn't allowed" ); |
| 347 | return std::__cxx_atomic_fetch_min(std::addressof(this->__a_), __op, __m); |
| 348 | } |
| 349 | #endif |
| 350 | |
| 351 | _LIBCPP_HIDE_FROM_ABI _Tp* operator++(int) volatile _NOEXCEPT { return fetch_add(1); } |
| 352 | _LIBCPP_HIDE_FROM_ABI _Tp* operator++(int) _NOEXCEPT { return fetch_add(1); } |
| 353 | _LIBCPP_HIDE_FROM_ABI _Tp* operator--(int) volatile _NOEXCEPT { return fetch_sub(1); } |
| 354 | _LIBCPP_HIDE_FROM_ABI _Tp* operator--(int) _NOEXCEPT { return fetch_sub(1); } |
| 355 | _LIBCPP_HIDE_FROM_ABI _Tp* operator++() volatile _NOEXCEPT { return fetch_add(1) + 1; } |
| 356 | _LIBCPP_HIDE_FROM_ABI _Tp* operator++() _NOEXCEPT { return fetch_add(1) + 1; } |
| 357 | _LIBCPP_HIDE_FROM_ABI _Tp* operator--() volatile _NOEXCEPT { return fetch_sub(1) - 1; } |
| 358 | _LIBCPP_HIDE_FROM_ABI _Tp* operator--() _NOEXCEPT { return fetch_sub(1) - 1; } |
| 359 | _LIBCPP_HIDE_FROM_ABI _Tp* operator+=(ptrdiff_t __op) volatile _NOEXCEPT { return fetch_add(__op) + __op; } |
| 360 | _LIBCPP_HIDE_FROM_ABI _Tp* operator+=(ptrdiff_t __op) _NOEXCEPT { return fetch_add(__op) + __op; } |
| 361 | _LIBCPP_HIDE_FROM_ABI _Tp* operator-=(ptrdiff_t __op) volatile _NOEXCEPT { return fetch_sub(__op) - __op; } |
| 362 | _LIBCPP_HIDE_FROM_ABI _Tp* operator-=(ptrdiff_t __op) _NOEXCEPT { return fetch_sub(__op) - __op; } |
| 363 | |
| 364 | atomic& operator=(const atomic&) = delete; |
| 365 | atomic& operator=(const atomic&) volatile = delete; |
| 366 | }; |
| 367 | |
| 368 | #if _LIBCPP_STD_VER >= 20 |
| 369 | template <class _Tp> |
| 370 | struct __atomic_waitable_traits<atomic<_Tp> > : __atomic_waitable_traits<__atomic_base<_Tp> > {}; |
| 371 | |
| 372 | template <class _Tp> |
| 373 | requires is_floating_point_v<_Tp> |
| 374 | struct atomic<_Tp> : __atomic_base<_Tp> { |
| 375 | private: |
| 376 | template <class _This, class _Operation, class _BuiltinOp> |
| 377 | _LIBCPP_HIDE_FROM_ABI static _Tp |
| 378 | __rmw_op(_This&& __self, _Tp __operand, memory_order __m, _Operation __operation, _BuiltinOp __builtin_op) { |
| 379 | if constexpr (std::__has_rmw_builtin<_Tp>()) { |
| 380 | return __builtin_op(std::addressof(std::forward<_This>(__self).__a_), __operand, __m); |
| 381 | } else { |
| 382 | _Tp __old = __self.load(memory_order_relaxed); |
| 383 | _Tp __new = __operation(__old, __operand); |
| 384 | while (!__self.compare_exchange_weak(__old, __new, __m, memory_order_relaxed)) { |
| 385 | # ifdef _LIBCPP_COMPILER_CLANG_BASED |
| 386 | if constexpr (std::__is_fp80_long_double<_Tp>()) { |
| 387 | // https://llvm.org/PR47978 |
| 388 | // clang bug: __old is not updated on failure for atomic<long double>::compare_exchange_weak |
| 389 | // Note __old = __self.load(memory_order_relaxed) will not work |
| 390 | std::__cxx_atomic_load_inplace(std::addressof(__self.__a_), std::addressof(__old), memory_order_relaxed); |
| 391 | } |
| 392 | # endif |
| 393 | __new = __operation(__old, __operand); |
| 394 | } |
| 395 | return __old; |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | template <class _This> |
| 400 | _LIBCPP_HIDE_FROM_ABI static _Tp __fetch_add(_This&& __self, _Tp __operand, memory_order __m) { |
| 401 | auto __builtin_op = [](auto __a, auto __builtin_operand, auto __order) { |
| 402 | return std::__cxx_atomic_fetch_add(__a, __builtin_operand, __order); |
| 403 | }; |
| 404 | auto __plus = [](auto __a, auto __b) { return __a + __b; }; |
| 405 | return __rmw_op(std::forward<_This>(__self), __operand, __m, __plus, __builtin_op); |
| 406 | } |
| 407 | |
| 408 | template <class _This> |
| 409 | _LIBCPP_HIDE_FROM_ABI static _Tp __fetch_sub(_This&& __self, _Tp __operand, memory_order __m) { |
| 410 | auto __builtin_op = [](auto __a, auto __builtin_operand, auto __order) { |
| 411 | return std::__cxx_atomic_fetch_sub(__a, __builtin_operand, __order); |
| 412 | }; |
| 413 | auto __minus = [](auto __a, auto __b) { return __a - __b; }; |
| 414 | return __rmw_op(std::forward<_This>(__self), __operand, __m, __minus, __builtin_op); |
| 415 | } |
| 416 | |
| 417 | public: |
| 418 | using __base _LIBCPP_NODEBUG = __atomic_base<_Tp>; |
| 419 | using value_type = _Tp; |
| 420 | using difference_type = value_type; |
| 421 | |
| 422 | _LIBCPP_HIDE_FROM_ABI constexpr atomic() noexcept = default; |
| 423 | _LIBCPP_HIDE_FROM_ABI constexpr atomic(_Tp __d) noexcept : __base(__d) {} |
| 424 | |
| 425 | atomic(const atomic&) = delete; |
| 426 | atomic& operator=(const atomic&) = delete; |
| 427 | atomic& operator=(const atomic&) volatile = delete; |
| 428 | |
| 429 | _LIBCPP_HIDE_FROM_ABI _Tp operator=(_Tp __d) volatile noexcept |
| 430 | requires __base::is_always_lock_free |
| 431 | { |
| 432 | __base::store(__d); |
| 433 | return __d; |
| 434 | } |
| 435 | _LIBCPP_HIDE_FROM_ABI _Tp operator=(_Tp __d) noexcept { |
| 436 | __base::store(__d); |
| 437 | return __d; |
| 438 | } |
| 439 | |
| 440 | _LIBCPP_HIDE_FROM_ABI _Tp fetch_add(_Tp __op, memory_order __m = memory_order_seq_cst) volatile noexcept |
| 441 | requires __base::is_always_lock_free |
| 442 | { |
| 443 | return __fetch_add(*this, __op, __m); |
| 444 | } |
| 445 | |
| 446 | _LIBCPP_HIDE_FROM_ABI _Tp fetch_add(_Tp __op, memory_order __m = memory_order_seq_cst) noexcept { |
| 447 | return __fetch_add(*this, __op, __m); |
| 448 | } |
| 449 | |
| 450 | _LIBCPP_HIDE_FROM_ABI _Tp fetch_sub(_Tp __op, memory_order __m = memory_order_seq_cst) volatile noexcept |
| 451 | requires __base::is_always_lock_free |
| 452 | { |
| 453 | return __fetch_sub(*this, __op, __m); |
| 454 | } |
| 455 | |
| 456 | _LIBCPP_HIDE_FROM_ABI _Tp fetch_sub(_Tp __op, memory_order __m = memory_order_seq_cst) noexcept { |
| 457 | return __fetch_sub(*this, __op, __m); |
| 458 | } |
| 459 | |
| 460 | _LIBCPP_HIDE_FROM_ABI _Tp operator+=(_Tp __op) volatile noexcept |
| 461 | requires __base::is_always_lock_free |
| 462 | { |
| 463 | return fetch_add(__op) + __op; |
| 464 | } |
| 465 | |
| 466 | _LIBCPP_HIDE_FROM_ABI _Tp operator+=(_Tp __op) noexcept { return fetch_add(__op) + __op; } |
| 467 | |
| 468 | _LIBCPP_HIDE_FROM_ABI _Tp operator-=(_Tp __op) volatile noexcept |
| 469 | requires __base::is_always_lock_free |
| 470 | { |
| 471 | return fetch_sub(__op) - __op; |
| 472 | } |
| 473 | |
| 474 | _LIBCPP_HIDE_FROM_ABI _Tp operator-=(_Tp __op) noexcept { return fetch_sub(__op) - __op; } |
| 475 | }; |
| 476 | |
| 477 | #endif // _LIBCPP_STD_VER >= 20 |
| 478 | |
| 479 | // atomic_is_lock_free |
| 480 | |
| 481 | template <class _Tp> |
| 482 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool atomic_is_lock_free(const volatile atomic<_Tp>* __o) _NOEXCEPT { |
| 483 | return __o->is_lock_free(); |
| 484 | } |
| 485 | |
| 486 | template <class _Tp> |
| 487 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool atomic_is_lock_free(const atomic<_Tp>* __o) _NOEXCEPT { |
| 488 | return __o->is_lock_free(); |
| 489 | } |
| 490 | |
| 491 | // atomic_init |
| 492 | |
| 493 | template <class _Tp> |
| 494 | _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_HIDE_FROM_ABI void |
| 495 | atomic_init(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d) _NOEXCEPT { |
| 496 | std::__cxx_atomic_init(std::addressof(__o->__a_), __d); |
| 497 | } |
| 498 | |
| 499 | template <class _Tp> |
| 500 | _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_HIDE_FROM_ABI void |
| 501 | atomic_init(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d) _NOEXCEPT { |
| 502 | std::__cxx_atomic_init(std::addressof(__o->__a_), __d); |
| 503 | } |
| 504 | |
| 505 | // atomic_store |
| 506 | |
| 507 | template <class _Tp> |
| 508 | _LIBCPP_HIDE_FROM_ABI void atomic_store(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d) _NOEXCEPT { |
| 509 | __o->store(__d); |
| 510 | } |
| 511 | |
| 512 | template <class _Tp> |
| 513 | _LIBCPP_HIDE_FROM_ABI void atomic_store(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d) _NOEXCEPT { |
| 514 | __o->store(__d); |
| 515 | } |
| 516 | |
| 517 | // atomic_store_explicit |
| 518 | |
| 519 | template <class _Tp> |
| 520 | _LIBCPP_HIDE_FROM_ABI void |
| 521 | atomic_store_explicit(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d, memory_order __m) _NOEXCEPT |
| 522 | _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) { |
| 523 | __o->store(__d, __m); |
| 524 | } |
| 525 | |
| 526 | template <class _Tp> |
| 527 | _LIBCPP_HIDE_FROM_ABI void |
| 528 | atomic_store_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d, memory_order __m) _NOEXCEPT |
| 529 | _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) { |
| 530 | __o->store(__d, __m); |
| 531 | } |
| 532 | |
| 533 | // atomic_load |
| 534 | |
| 535 | template <class _Tp> |
| 536 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _Tp atomic_load(const volatile atomic<_Tp>* __o) _NOEXCEPT { |
| 537 | return __o->load(); |
| 538 | } |
| 539 | |
| 540 | template <class _Tp> |
| 541 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _Tp atomic_load(const atomic<_Tp>* __o) _NOEXCEPT { |
| 542 | return __o->load(); |
| 543 | } |
| 544 | |
| 545 | // atomic_load_explicit |
| 546 | |
| 547 | template <class _Tp> |
| 548 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _Tp |
| 549 | atomic_load_explicit(const volatile atomic<_Tp>* __o, memory_order __m) _NOEXCEPT _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) { |
| 550 | return __o->load(__m); |
| 551 | } |
| 552 | |
| 553 | template <class _Tp> |
| 554 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _Tp atomic_load_explicit(const atomic<_Tp>* __o, memory_order __m) _NOEXCEPT |
| 555 | _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) { |
| 556 | return __o->load(__m); |
| 557 | } |
| 558 | |
| 559 | // atomic_exchange |
| 560 | |
| 561 | template <class _Tp> |
| 562 | _LIBCPP_HIDE_FROM_ABI _Tp atomic_exchange(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d) _NOEXCEPT { |
| 563 | return __o->exchange(__d); |
| 564 | } |
| 565 | |
| 566 | template <class _Tp> |
| 567 | _LIBCPP_HIDE_FROM_ABI _Tp atomic_exchange(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d) _NOEXCEPT { |
| 568 | return __o->exchange(__d); |
| 569 | } |
| 570 | |
| 571 | // atomic_exchange_explicit |
| 572 | |
| 573 | template <class _Tp> |
| 574 | _LIBCPP_HIDE_FROM_ABI _Tp |
| 575 | atomic_exchange_explicit(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d, memory_order __m) _NOEXCEPT { |
| 576 | return __o->exchange(__d, __m); |
| 577 | } |
| 578 | |
| 579 | template <class _Tp> |
| 580 | _LIBCPP_HIDE_FROM_ABI _Tp |
| 581 | atomic_exchange_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d, memory_order __m) _NOEXCEPT { |
| 582 | return __o->exchange(__d, __m); |
| 583 | } |
| 584 | |
| 585 | // atomic_compare_exchange_weak |
| 586 | |
| 587 | template <class _Tp> |
| 588 | _LIBCPP_HIDE_FROM_ABI bool atomic_compare_exchange_weak( |
| 589 | volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type* __e, typename atomic<_Tp>::value_type __d) _NOEXCEPT { |
| 590 | return __o->compare_exchange_weak(*__e, __d); |
| 591 | } |
| 592 | |
| 593 | template <class _Tp> |
| 594 | _LIBCPP_HIDE_FROM_ABI bool atomic_compare_exchange_weak( |
| 595 | atomic<_Tp>* __o, typename atomic<_Tp>::value_type* __e, typename atomic<_Tp>::value_type __d) _NOEXCEPT { |
| 596 | return __o->compare_exchange_weak(*__e, __d); |
| 597 | } |
| 598 | |
| 599 | // atomic_compare_exchange_strong |
| 600 | |
| 601 | template <class _Tp> |
| 602 | _LIBCPP_HIDE_FROM_ABI bool atomic_compare_exchange_strong( |
| 603 | volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type* __e, typename atomic<_Tp>::value_type __d) _NOEXCEPT { |
| 604 | return __o->compare_exchange_strong(*__e, __d); |
| 605 | } |
| 606 | |
| 607 | template <class _Tp> |
| 608 | _LIBCPP_HIDE_FROM_ABI bool atomic_compare_exchange_strong( |
| 609 | atomic<_Tp>* __o, typename atomic<_Tp>::value_type* __e, typename atomic<_Tp>::value_type __d) _NOEXCEPT { |
| 610 | return __o->compare_exchange_strong(*__e, __d); |
| 611 | } |
| 612 | |
| 613 | // atomic_compare_exchange_weak_explicit |
| 614 | |
| 615 | template <class _Tp> |
| 616 | _LIBCPP_HIDE_FROM_ABI bool atomic_compare_exchange_weak_explicit( |
| 617 | volatile atomic<_Tp>* __o, |
| 618 | typename atomic<_Tp>::value_type* __e, |
| 619 | typename atomic<_Tp>::value_type __d, |
| 620 | memory_order __s, |
| 621 | memory_order __f) _NOEXCEPT _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) { |
| 622 | return __o->compare_exchange_weak(*__e, __d, __s, __f); |
| 623 | } |
| 624 | |
| 625 | template <class _Tp> |
| 626 | _LIBCPP_HIDE_FROM_ABI bool atomic_compare_exchange_weak_explicit( |
| 627 | atomic<_Tp>* __o, |
| 628 | typename atomic<_Tp>::value_type* __e, |
| 629 | typename atomic<_Tp>::value_type __d, |
| 630 | memory_order __s, |
| 631 | memory_order __f) _NOEXCEPT _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) { |
| 632 | return __o->compare_exchange_weak(*__e, __d, __s, __f); |
| 633 | } |
| 634 | |
| 635 | // atomic_compare_exchange_strong_explicit |
| 636 | |
| 637 | template <class _Tp> |
| 638 | _LIBCPP_HIDE_FROM_ABI bool atomic_compare_exchange_strong_explicit( |
| 639 | volatile atomic<_Tp>* __o, |
| 640 | typename atomic<_Tp>::value_type* __e, |
| 641 | typename atomic<_Tp>::value_type __d, |
| 642 | memory_order __s, |
| 643 | memory_order __f) _NOEXCEPT _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) { |
| 644 | return __o->compare_exchange_strong(*__e, __d, __s, __f); |
| 645 | } |
| 646 | |
| 647 | template <class _Tp> |
| 648 | _LIBCPP_HIDE_FROM_ABI bool atomic_compare_exchange_strong_explicit( |
| 649 | atomic<_Tp>* __o, |
| 650 | typename atomic<_Tp>::value_type* __e, |
| 651 | typename atomic<_Tp>::value_type __d, |
| 652 | memory_order __s, |
| 653 | memory_order __f) _NOEXCEPT _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) { |
| 654 | return __o->compare_exchange_strong(*__e, __d, __s, __f); |
| 655 | } |
| 656 | |
| 657 | #if _LIBCPP_STD_VER >= 20 |
| 658 | |
| 659 | // atomic_wait |
| 660 | |
| 661 | template <class _Tp> |
| 662 | _LIBCPP_HIDE_FROM_ABI void atomic_wait(const volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __v) noexcept { |
| 663 | return __o->wait(__v); |
| 664 | } |
| 665 | |
| 666 | template <class _Tp> |
| 667 | _LIBCPP_HIDE_FROM_ABI void atomic_wait(const atomic<_Tp>* __o, typename atomic<_Tp>::value_type __v) noexcept { |
| 668 | return __o->wait(__v); |
| 669 | } |
| 670 | |
| 671 | // atomic_wait_explicit |
| 672 | |
| 673 | template <class _Tp> |
| 674 | _LIBCPP_HIDE_FROM_ABI void |
| 675 | atomic_wait_explicit(const volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __v, memory_order __m) noexcept |
| 676 | _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) { |
| 677 | return __o->wait(__v, __m); |
| 678 | } |
| 679 | |
| 680 | template <class _Tp> |
| 681 | _LIBCPP_HIDE_FROM_ABI void |
| 682 | atomic_wait_explicit(const atomic<_Tp>* __o, typename atomic<_Tp>::value_type __v, memory_order __m) noexcept |
| 683 | _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) { |
| 684 | return __o->wait(__v, __m); |
| 685 | } |
| 686 | |
| 687 | // atomic_notify_one |
| 688 | |
| 689 | template <class _Tp> |
| 690 | _LIBCPP_HIDE_FROM_ABI void atomic_notify_one(volatile atomic<_Tp>* __o) noexcept { |
| 691 | __o->notify_one(); |
| 692 | } |
| 693 | template <class _Tp> |
| 694 | _LIBCPP_HIDE_FROM_ABI void atomic_notify_one(atomic<_Tp>* __o) noexcept { |
| 695 | __o->notify_one(); |
| 696 | } |
| 697 | |
| 698 | // atomic_notify_all |
| 699 | |
| 700 | template <class _Tp> |
| 701 | _LIBCPP_HIDE_FROM_ABI void atomic_notify_all(volatile atomic<_Tp>* __o) noexcept { |
| 702 | __o->notify_all(); |
| 703 | } |
| 704 | template <class _Tp> |
| 705 | _LIBCPP_HIDE_FROM_ABI void atomic_notify_all(atomic<_Tp>* __o) noexcept { |
| 706 | __o->notify_all(); |
| 707 | } |
| 708 | |
| 709 | #endif // _LIBCPP_STD_VER >= 20 |
| 710 | |
| 711 | // atomic_fetch_add |
| 712 | |
| 713 | template <class _Tp> |
| 714 | _LIBCPP_HIDE_FROM_ABI _Tp |
| 715 | atomic_fetch_add(volatile atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op) _NOEXCEPT { |
| 716 | return __o->fetch_add(__op); |
| 717 | } |
| 718 | |
| 719 | template <class _Tp> |
| 720 | _LIBCPP_HIDE_FROM_ABI _Tp atomic_fetch_add(atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op) _NOEXCEPT { |
| 721 | return __o->fetch_add(__op); |
| 722 | } |
| 723 | |
| 724 | // atomic_fetch_add_explicit |
| 725 | |
| 726 | template <class _Tp> |
| 727 | _LIBCPP_HIDE_FROM_ABI _Tp atomic_fetch_add_explicit( |
| 728 | volatile atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op, memory_order __m) _NOEXCEPT { |
| 729 | return __o->fetch_add(__op, __m); |
| 730 | } |
| 731 | |
| 732 | template <class _Tp> |
| 733 | _LIBCPP_HIDE_FROM_ABI _Tp |
| 734 | atomic_fetch_add_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op, memory_order __m) _NOEXCEPT { |
| 735 | return __o->fetch_add(__op, __m); |
| 736 | } |
| 737 | |
| 738 | // atomic_fetch_sub |
| 739 | |
| 740 | template <class _Tp> |
| 741 | _LIBCPP_HIDE_FROM_ABI _Tp |
| 742 | atomic_fetch_sub(volatile atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op) _NOEXCEPT { |
| 743 | return __o->fetch_sub(__op); |
| 744 | } |
| 745 | |
| 746 | template <class _Tp> |
| 747 | _LIBCPP_HIDE_FROM_ABI _Tp atomic_fetch_sub(atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op) _NOEXCEPT { |
| 748 | return __o->fetch_sub(__op); |
| 749 | } |
| 750 | |
| 751 | // atomic_fetch_sub_explicit |
| 752 | |
| 753 | template <class _Tp> |
| 754 | _LIBCPP_HIDE_FROM_ABI _Tp atomic_fetch_sub_explicit( |
| 755 | volatile atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op, memory_order __m) _NOEXCEPT { |
| 756 | return __o->fetch_sub(__op, __m); |
| 757 | } |
| 758 | |
| 759 | template <class _Tp> |
| 760 | _LIBCPP_HIDE_FROM_ABI _Tp |
| 761 | atomic_fetch_sub_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op, memory_order __m) _NOEXCEPT { |
| 762 | return __o->fetch_sub(__op, __m); |
| 763 | } |
| 764 | |
| 765 | // atomic_fetch_and |
| 766 | |
| 767 | template <class _Tp, __enable_if_t<is_integral<_Tp>::value && !is_same<_Tp, bool>::value, int> = 0> |
| 768 | _LIBCPP_HIDE_FROM_ABI _Tp atomic_fetch_and(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op) _NOEXCEPT { |
| 769 | return __o->fetch_and(__op); |
| 770 | } |
| 771 | |
| 772 | template <class _Tp, __enable_if_t<is_integral<_Tp>::value && !is_same<_Tp, bool>::value, int> = 0> |
| 773 | _LIBCPP_HIDE_FROM_ABI _Tp atomic_fetch_and(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op) _NOEXCEPT { |
| 774 | return __o->fetch_and(__op); |
| 775 | } |
| 776 | |
| 777 | // atomic_fetch_and_explicit |
| 778 | |
| 779 | template <class _Tp, __enable_if_t<is_integral<_Tp>::value && !is_same<_Tp, bool>::value, int> = 0> |
| 780 | _LIBCPP_HIDE_FROM_ABI _Tp atomic_fetch_and_explicit( |
| 781 | volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op, memory_order __m) _NOEXCEPT { |
| 782 | return __o->fetch_and(__op, __m); |
| 783 | } |
| 784 | |
| 785 | template <class _Tp, __enable_if_t<is_integral<_Tp>::value && !is_same<_Tp, bool>::value, int> = 0> |
| 786 | _LIBCPP_HIDE_FROM_ABI _Tp |
| 787 | atomic_fetch_and_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op, memory_order __m) _NOEXCEPT { |
| 788 | return __o->fetch_and(__op, __m); |
| 789 | } |
| 790 | |
| 791 | // atomic_fetch_or |
| 792 | |
| 793 | template <class _Tp, __enable_if_t<is_integral<_Tp>::value && !is_same<_Tp, bool>::value, int> = 0> |
| 794 | _LIBCPP_HIDE_FROM_ABI _Tp atomic_fetch_or(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op) _NOEXCEPT { |
| 795 | return __o->fetch_or(__op); |
| 796 | } |
| 797 | |
| 798 | template <class _Tp, __enable_if_t<is_integral<_Tp>::value && !is_same<_Tp, bool>::value, int> = 0> |
| 799 | _LIBCPP_HIDE_FROM_ABI _Tp atomic_fetch_or(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op) _NOEXCEPT { |
| 800 | return __o->fetch_or(__op); |
| 801 | } |
| 802 | |
| 803 | // atomic_fetch_or_explicit |
| 804 | |
| 805 | template <class _Tp, __enable_if_t<is_integral<_Tp>::value && !is_same<_Tp, bool>::value, int> = 0> |
| 806 | _LIBCPP_HIDE_FROM_ABI _Tp |
| 807 | atomic_fetch_or_explicit(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op, memory_order __m) _NOEXCEPT { |
| 808 | return __o->fetch_or(__op, __m); |
| 809 | } |
| 810 | |
| 811 | template <class _Tp, __enable_if_t<is_integral<_Tp>::value && !is_same<_Tp, bool>::value, int> = 0> |
| 812 | _LIBCPP_HIDE_FROM_ABI _Tp |
| 813 | atomic_fetch_or_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op, memory_order __m) _NOEXCEPT { |
| 814 | return __o->fetch_or(__op, __m); |
| 815 | } |
| 816 | |
| 817 | // atomic_fetch_xor |
| 818 | |
| 819 | template <class _Tp, __enable_if_t<is_integral<_Tp>::value && !is_same<_Tp, bool>::value, int> = 0> |
| 820 | _LIBCPP_HIDE_FROM_ABI _Tp atomic_fetch_xor(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op) _NOEXCEPT { |
| 821 | return __o->fetch_xor(__op); |
| 822 | } |
| 823 | |
| 824 | template <class _Tp, __enable_if_t<is_integral<_Tp>::value && !is_same<_Tp, bool>::value, int> = 0> |
| 825 | _LIBCPP_HIDE_FROM_ABI _Tp atomic_fetch_xor(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op) _NOEXCEPT { |
| 826 | return __o->fetch_xor(__op); |
| 827 | } |
| 828 | |
| 829 | // atomic_fetch_xor_explicit |
| 830 | |
| 831 | template <class _Tp, __enable_if_t<is_integral<_Tp>::value && !is_same<_Tp, bool>::value, int> = 0> |
| 832 | _LIBCPP_HIDE_FROM_ABI _Tp atomic_fetch_xor_explicit( |
| 833 | volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op, memory_order __m) _NOEXCEPT { |
| 834 | return __o->fetch_xor(__op, __m); |
| 835 | } |
| 836 | |
| 837 | template <class _Tp, __enable_if_t<is_integral<_Tp>::value && !is_same<_Tp, bool>::value, int> = 0> |
| 838 | _LIBCPP_HIDE_FROM_ABI _Tp |
| 839 | atomic_fetch_xor_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op, memory_order __m) _NOEXCEPT { |
| 840 | return __o->fetch_xor(__op, __m); |
| 841 | } |
| 842 | |
| 843 | #if _LIBCPP_STD_VER >= 26 |
| 844 | // atomic_fetch_max |
| 845 | |
| 846 | template <class _Tp> |
| 847 | requires((integral<_Tp> && !same_as<_Tp, bool>) || is_pointer_v<_Tp>) |
| 848 | _LIBCPP_HIDE_FROM_ABI _Tp atomic_fetch_max(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op) noexcept { |
| 849 | return __o->fetch_max(__op); |
| 850 | } |
| 851 | |
| 852 | template <class _Tp> |
| 853 | requires((integral<_Tp> && !same_as<_Tp, bool>) || is_pointer_v<_Tp>) |
| 854 | _LIBCPP_HIDE_FROM_ABI _Tp atomic_fetch_max(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op) noexcept { |
| 855 | return __o->fetch_max(__op); |
| 856 | } |
| 857 | |
| 858 | // atomic_fetch_max_explicit |
| 859 | |
| 860 | template <class _Tp> |
| 861 | requires((integral<_Tp> && !same_as<_Tp, bool>) || is_pointer_v<_Tp>) |
| 862 | _LIBCPP_HIDE_FROM_ABI _Tp |
| 863 | atomic_fetch_max_explicit(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op, memory_order __m) noexcept { |
| 864 | return __o->fetch_max(__op, __m); |
| 865 | } |
| 866 | |
| 867 | template <class _Tp> |
| 868 | requires((integral<_Tp> && !same_as<_Tp, bool>) || is_pointer_v<_Tp>) |
| 869 | _LIBCPP_HIDE_FROM_ABI _Tp |
| 870 | atomic_fetch_max_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op, memory_order __m) noexcept { |
| 871 | return __o->fetch_max(__op, __m); |
| 872 | } |
| 873 | |
| 874 | // atomic_fetch_min |
| 875 | |
| 876 | template <class _Tp> |
| 877 | requires((integral<_Tp> && !same_as<_Tp, bool>) || is_pointer_v<_Tp>) |
| 878 | _LIBCPP_HIDE_FROM_ABI _Tp atomic_fetch_min(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op) noexcept { |
| 879 | return __o->fetch_min(__op); |
| 880 | } |
| 881 | |
| 882 | template <class _Tp> |
| 883 | requires((integral<_Tp> && !same_as<_Tp, bool>) || is_pointer_v<_Tp>) |
| 884 | _LIBCPP_HIDE_FROM_ABI _Tp atomic_fetch_min(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op) noexcept { |
| 885 | return __o->fetch_min(__op); |
| 886 | } |
| 887 | |
| 888 | // atomic_fetch_min_explicit |
| 889 | |
| 890 | template <class _Tp> |
| 891 | requires((integral<_Tp> && !same_as<_Tp, bool>) || is_pointer_v<_Tp>) |
| 892 | _LIBCPP_HIDE_FROM_ABI _Tp |
| 893 | atomic_fetch_min_explicit(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op, memory_order __m) noexcept { |
| 894 | return __o->fetch_min(__op, __m); |
| 895 | } |
| 896 | |
| 897 | template <class _Tp> |
| 898 | requires((integral<_Tp> && !same_as<_Tp, bool>) || is_pointer_v<_Tp>) |
| 899 | _LIBCPP_HIDE_FROM_ABI _Tp |
| 900 | atomic_fetch_min_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op, memory_order __m) noexcept { |
| 901 | return __o->fetch_min(__op, __m); |
| 902 | } |
| 903 | #endif |
| 904 | |
| 905 | _LIBCPP_END_NAMESPACE_STD |
| 906 | |
| 907 | #endif // _LIBCPP___ATOMIC_ATOMIC_H |
| 908 | |