30#ifndef _SHARED_PTR_ATOMIC_H
31#define _SHARED_PTR_ATOMIC_H 1
35namespace std _GLIBCXX_VISIBILITY(default)
37_GLIBCXX_BEGIN_NAMESPACE_VERSION
49 _Sp_locker(
const _Sp_locker&) =
delete;
50 _Sp_locker& operator=(
const _Sp_locker&) =
delete;
54 _Sp_locker(
const void*)
noexcept;
55 _Sp_locker(
const void*,
const void*)
noexcept;
59 unsigned char _M_key1;
60 unsigned char _M_key2;
62 explicit _Sp_locker(
const void*,
const void* =
nullptr) { }
74 template<
typename _Tp, _Lock_policy _Lp>
79 return __gthread_active_p() == 0;
85 template<
typename _Tp>
88 {
return std::atomic_is_lock_free<_Tp, __default_lock_policy>(__p); }
101 template<
typename _Tp>
102 inline shared_ptr<_Tp>
105 _Sp_locker __lock{__p};
109 template<
typename _Tp>
112 {
return std::atomic_load_explicit(__p, memory_order_seq_cst); }
114 template<
typename _Tp, _Lock_policy _Lp>
115 inline __shared_ptr<_Tp, _Lp>
116 atomic_load_explicit(
const __shared_ptr<_Tp, _Lp>* __p,
memory_order)
118 _Sp_locker __lock{__p};
122 template<
typename _Tp, _Lock_policy _Lp>
123 inline __shared_ptr<_Tp, _Lp>
124 atomic_load(
const __shared_ptr<_Tp, _Lp>* __p)
125 {
return std::atomic_load_explicit(__p, memory_order_seq_cst); }
137 template<
typename _Tp>
142 _Sp_locker __lock{__p};
146 template<
typename _Tp>
149 { std::atomic_store_explicit(__p,
std::move(__r), memory_order_seq_cst); }
151 template<
typename _Tp, _Lock_policy _Lp>
153 atomic_store_explicit(__shared_ptr<_Tp, _Lp>* __p,
154 __shared_ptr<_Tp, _Lp> __r,
157 _Sp_locker __lock{__p};
161 template<
typename _Tp, _Lock_policy _Lp>
163 atomic_store(__shared_ptr<_Tp, _Lp>* __p, __shared_ptr<_Tp, _Lp> __r)
164 { std::atomic_store_explicit(__p,
std::move(__r), memory_order_seq_cst); }
174 template<
typename _Tp>
175 inline shared_ptr<_Tp>
179 _Sp_locker __lock{__p};
184 template<
typename _Tp>
188 return std::atomic_exchange_explicit(__p,
std::move(__r),
189 memory_order_seq_cst);
192 template<
typename _Tp, _Lock_policy _Lp>
193 inline __shared_ptr<_Tp, _Lp>
194 atomic_exchange_explicit(__shared_ptr<_Tp, _Lp>* __p,
195 __shared_ptr<_Tp, _Lp> __r,
198 _Sp_locker __lock{__p};
203 template<
typename _Tp, _Lock_policy _Lp>
204 inline __shared_ptr<_Tp, _Lp>
205 atomic_exchange(__shared_ptr<_Tp, _Lp>* __p, __shared_ptr<_Tp, _Lp> __r)
207 return std::atomic_exchange_explicit(__p,
std::move(__r),
208 memory_order_seq_cst);
223 template<
typename _Tp>
232 _Sp_locker __lock{__p, __v};
234 if (*__p == *__v && !__less(*__p, *__v) && !__less(*__v, *__p))
245 template<
typename _Tp>
250 return std::atomic_compare_exchange_strong_explicit(__p, __v,
251 std::move(__w), memory_order_seq_cst, memory_order_seq_cst);
254 template<
typename _Tp>
256 atomic_compare_exchange_weak_explicit(shared_ptr<_Tp>* __p,
257 shared_ptr<_Tp>* __v,
262 return std::atomic_compare_exchange_strong_explicit(__p, __v,
266 template<
typename _Tp>
268 atomic_compare_exchange_weak(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
271 return std::atomic_compare_exchange_weak_explicit(__p, __v,
272 std::move(__w), memory_order_seq_cst, memory_order_seq_cst);
275 template<
typename _Tp, _Lock_policy _Lp>
277 atomic_compare_exchange_strong_explicit(__shared_ptr<_Tp, _Lp>* __p,
278 __shared_ptr<_Tp, _Lp>* __v,
279 __shared_ptr<_Tp, _Lp> __w,
283 __shared_ptr<_Tp, _Lp> __x;
284 _Sp_locker __lock{__p, __v};
285 owner_less<__shared_ptr<_Tp, _Lp>> __less;
286 if (*__p == *__v && !__less(*__p, *__v) && !__less(*__v, *__p))
297 template<
typename _Tp, _Lock_policy _Lp>
299 atomic_compare_exchange_strong(__shared_ptr<_Tp, _Lp>* __p,
300 __shared_ptr<_Tp, _Lp>* __v,
301 __shared_ptr<_Tp, _Lp> __w)
303 return std::atomic_compare_exchange_strong_explicit(__p, __v,
304 std::move(__w), memory_order_seq_cst, memory_order_seq_cst);
307 template<
typename _Tp, _Lock_policy _Lp>
309 atomic_compare_exchange_weak_explicit(__shared_ptr<_Tp, _Lp>* __p,
310 __shared_ptr<_Tp, _Lp>* __v,
311 __shared_ptr<_Tp, _Lp> __w,
315 return std::atomic_compare_exchange_strong_explicit(__p, __v,
319 template<
typename _Tp, _Lock_policy _Lp>
321 atomic_compare_exchange_weak(__shared_ptr<_Tp, _Lp>* __p,
322 __shared_ptr<_Tp, _Lp>* __v,
323 __shared_ptr<_Tp, _Lp> __w)
325 return std::atomic_compare_exchange_weak_explicit(__p, __v,
326 std::move(__w), memory_order_seq_cst, memory_order_seq_cst);
333_GLIBCXX_END_NAMESPACE_VERSION
shared_ptr< _Tp > atomic_exchange_explicit(shared_ptr< _Tp > *__p, shared_ptr< _Tp > __r, memory_order)
Atomic exchange for shared_ptr objects.
bool atomic_compare_exchange_strong_explicit(shared_ptr< _Tp > *__p, shared_ptr< _Tp > *__v, shared_ptr< _Tp > __w, memory_order, memory_order)
Atomic compare-and-swap for shared_ptr objects.
void atomic_store_explicit(shared_ptr< _Tp > *__p, shared_ptr< _Tp > __r, memory_order)
Atomic store for shared_ptr objects.
bool atomic_is_lock_free(const __shared_ptr< _Tp, _Lp > *__p)
Report whether shared_ptr atomic operations are lock-free.
void swap(shared_ptr< _Tp > &__a, shared_ptr< _Tp > &__b) noexcept
Swap overload for shared_ptr.
shared_ptr< _Tp > atomic_load_explicit(const shared_ptr< _Tp > *__p, memory_order)
Atomic load for shared_ptr objects.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
memory_order
Enumeration for memory_order.
ISO C++ entities toplevel namespace is std.
A smart pointer with reference-counted copy semantics.
Primary template owner_less.