Implement [util.smartptr.shared.atomic]. This is the last unimplemented · llvm-mirror/libcxx@5fec82d (original) (raw)
`@@ -602,6 +602,10 @@ void* align(size_t alignment, size_t size, void*& ptr, size_t& space);
`
602
602
` #include
`
603
603
`#endif
`
604
604
``
``
605
`+
#if __has_feature(cxx_atomic)
`
``
606
`+
include
`
``
607
`+
#endif
`
``
608
+
605
609
`#include <__undef_min_max>
`
606
610
``
607
611
`#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
`
`@@ -3387,8 +3391,19 @@ struct __scalar_hash<_Tp, 4>
`
3387
3391
``
3388
3392
`template
`
3389
3393
`struct _LIBCPP_VISIBLE hash<_Tp*>
`
3390
``
`-
: public __scalar_hash<_Tp*>
`
``
3394
`+
: public unary_function<_Tp*, size_t>
`
3391
3395
`{
`
``
3396
`+
_LIBCPP_INLINE_VISIBILITY
`
``
3397
`+
size_t operator()(_Tp* __v) const _NOEXCEPT
`
``
3398
`+
{
`
``
3399
`+
union
`
``
3400
`+
{
`
``
3401
`+
_Tp* __t;
`
``
3402
`+
size_t __a;
`
``
3403
`+
} __u;
`
``
3404
`+
__u.__t = __v;
`
``
3405
`+
return __murmur2_or_cityhash()(&__u, sizeof(__u));
`
``
3406
`+
}
`
3392
3407
`};
`
3393
3408
``
3394
3409
`template <class _Tp, class _Dp>
`
`@@ -3934,6 +3949,10 @@ public:
`
3934
3949
` _LIBCPP_INLINE_VISIBILITY
`
3935
3950
`bool owner_before(weak_ptr<_Up> const& __p) const
`
3936
3951
` {return _cntrl < __p._cntrl;}
`
``
3952
`+
_LIBCPP_INLINE_VISIBILITY
`
``
3953
`+
bool
`
``
3954
`+
__owner_equivalent(const shared_ptr& __p) const
`
``
3955
`+
{return _cntrl == __p._cntrl;}
`
3937
3956
``
3938
3957
`#ifndef _LIBCPP_NO_RTTI
`
3939
3958
`template
`
`@@ -5245,6 +5264,134 @@ inline _LIBCPP_INLINE_VISIBILITY
`
5245
5264
`basic_ostream<_CharT, _Traits>&
`
5246
5265
`operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p);
`
5247
5266
``
``
5267
`+
#if __has_feature(cxx_atomic)
`
``
5268
+
``
5269
`+
class __sp_mut
`
``
5270
`+
{
`
``
5271
`+
void* _;
`
``
5272
`+
public:
`
``
5273
`+
void lock() _NOEXCEPT;
`
``
5274
`+
void unlock() _NOEXCEPT;
`
``
5275
+
``
5276
`+
private:
`
``
5277
`+
_LIBCPP_CONSTEXPR __sp_mut(void*) _NOEXCEPT;
`
``
5278
`+
__sp_mut(const __sp_mut&);
`
``
5279
`+
__sp_mut& operator=(const __sp_mut&);
`
``
5280
+
``
5281
`+
friend __sp_mut& __get_sp_mut(const void*);
`
``
5282
`+
};
`
``
5283
+
``
5284
`+
__sp_mut& __get_sp_mut(const void*);
`
``
5285
+
``
5286
`+
template
`
``
5287
`+
inline _LIBCPP_INLINE_VISIBILITY
`
``
5288
`+
bool
`
``
5289
`+
atomic_is_lock_free(const shared_ptr<_Tp>*)
`
``
5290
`+
{
`
``
5291
`+
return false;
`
``
5292
`+
}
`
``
5293
+
``
5294
`+
template
`
``
5295
`+
shared_ptr<_Tp>
`
``
5296
`+
atomic_load(const shared_ptr<_Tp>* __p)
`
``
5297
`+
{
`
``
5298
`+
__sp_mut& __m = __get_sp_mut(__p);
`
``
5299
`+
__m.lock();
`
``
5300
`+
shared_ptr<_Tp> __q = *__p;
`
``
5301
`+
__m.unlock();
`
``
5302
`+
return __q;
`
``
5303
`+
}
`
``
5304
+
``
5305
`+
template
`
``
5306
`+
inline _LIBCPP_INLINE_VISIBILITY
`
``
5307
`+
shared_ptr<_Tp>
`
``
5308
`+
atomic_load_explicit(const shared_ptr<_Tp>* __p, memory_order)
`
``
5309
`+
{
`
``
5310
`+
return atomic_load(__p);
`
``
5311
`+
}
`
``
5312
+
``
5313
`+
template
`
``
5314
`+
void
`
``
5315
`+
atomic_store(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r)
`
``
5316
`+
{
`
``
5317
`+
__sp_mut& __m = __get_sp_mut(__p);
`
``
5318
`+
__m.lock();
`
``
5319
`+
__p->swap(__r);
`
``
5320
`+
__m.unlock();
`
``
5321
`+
}
`
``
5322
+
``
5323
`+
template
`
``
5324
`+
inline _LIBCPP_INLINE_VISIBILITY
`
``
5325
`+
void
`
``
5326
`+
atomic_store_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order)
`
``
5327
`+
{
`
``
5328
`+
atomic_store(__p, __r);
`
``
5329
`+
}
`
``
5330
+
``
5331
`+
template
`
``
5332
`+
shared_ptr<_Tp>
`
``
5333
`+
atomic_exchange(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r)
`
``
5334
`+
{
`
``
5335
`+
__sp_mut& __m = __get_sp_mut(__p);
`
``
5336
`+
__m.lock();
`
``
5337
`+
__p->swap(__r);
`
``
5338
`+
__m.unlock();
`
``
5339
`+
return __r;
`
``
5340
`+
}
`
``
5341
+
``
5342
`+
template
`
``
5343
`+
inline _LIBCPP_INLINE_VISIBILITY
`
``
5344
`+
shared_ptr<_Tp>
`
``
5345
`+
atomic_exchange_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order)
`
``
5346
`+
{
`
``
5347
`+
return atomic_exchange(__p, __r);
`
``
5348
`+
}
`
``
5349
+
``
5350
`+
template
`
``
5351
`+
bool
`
``
5352
`+
atomic_compare_exchange_strong(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
`
``
5353
`+
{
`
``
5354
`+
__sp_mut& __m = __get_sp_mut(__p);
`
``
5355
`+
__m.lock();
`
``
5356
`+
if (__p->__owner_equivalent(*__v))
`
``
5357
`+
{
`
``
5358
`+
*__p = __w;
`
``
5359
`+
__m.unlock();
`
``
5360
`+
return true;
`
``
5361
`+
}
`
``
5362
`+
*__v = *__p;
`
``
5363
`+
__m.unlock();
`
``
5364
`+
return false;
`
``
5365
`+
}
`
``
5366
+
``
5367
`+
template
`
``
5368
`+
inline _LIBCPP_INLINE_VISIBILITY
`
``
5369
`+
bool
`
``
5370
`+
atomic_compare_exchange_weak(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
`
``
5371
`+
{
`
``
5372
`+
return atomic_compare_exchange_strong(__p, __v, __w);
`
``
5373
`+
}
`
``
5374
+
``
5375
`+
template
`
``
5376
`+
inline _LIBCPP_INLINE_VISIBILITY
`
``
5377
`+
bool
`
``
5378
`+
atomic_compare_exchange_strong_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
`
``
5379
`+
shared_ptr<_Tp> __w, memory_order, memory_order)
`
``
5380
`+
{
`
``
5381
`+
return atomic_compare_exchange_strong(__p, __v, __w);
`
``
5382
`+
}
`
``
5383
+
``
5384
`+
template
`
``
5385
`+
inline _LIBCPP_INLINE_VISIBILITY
`
``
5386
`+
bool
`
``
5387
`+
atomic_compare_exchange_weak_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
`
``
5388
`+
shared_ptr<_Tp> __w, memory_order, memory_order)
`
``
5389
`+
{
`
``
5390
`+
return atomic_compare_exchange_weak(__p, __v, __w);
`
``
5391
`+
}
`
``
5392
+
``
5393
`+
#endif // __has_feature(cxx_atomic)
`
``
5394
+
5248
5395
`//enum class
`
5249
5396
`struct _LIBCPP_VISIBLE pointer_safety
`
5250
5397
`{
`