123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- diff --git a/include/__memory/shared_ptr.h b/include/__memory/shared_ptr.h
- index a8ff189..fa25116 100644
- --- a/include/__memory/shared_ptr.h
- +++ b/include/__memory/shared_ptr.h
- @@ -53,7 +53,7 @@
- #include <new>
- #include <typeinfo>
- #if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
- -# include <__atomic/memory_order.h>
- +# include <atomic>
- #endif
-
- #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
- @@ -137,7 +137,12 @@ class _LIBCPP_EXPORTED_FROM_ABI __shared_count {
- __shared_count& operator=(const __shared_count&);
-
- protected:
- - long __shared_owners_;
- +#ifdef _LIBCPP_HAS_NO_THREADS
- + typedef long __atomic_count;
- +#else
- + typedef atomic<long> __atomic_count;
- +#endif
- + __atomic_count __shared_owners_;
- virtual ~__shared_count();
-
- private:
- @@ -150,20 +155,41 @@ public:
- void __add_shared() noexcept;
- bool __release_shared() noexcept;
- #else
- - _LIBCPP_HIDE_FROM_ABI void __add_shared() _NOEXCEPT { __libcpp_atomic_refcount_increment(__shared_owners_); }
- + _LIBCPP_HIDE_FROM_ABI void __add_shared() _NOEXCEPT {
- +# ifdef _LIBCPP_HAS_NO_THREADS
- + __libcpp_atomic_refcount_increment(__shared_owners_);
- +# else
- + __shared_owners_++;
- +# endif
- + }
- _LIBCPP_HIDE_FROM_ABI bool __release_shared() _NOEXCEPT {
- +# ifdef _LIBCPP_HAS_NO_THREADS
- if (__libcpp_atomic_refcount_decrement(__shared_owners_) == -1) {
- +# else
- + if (--__shared_owners_ == -1) {
- +# endif
- __on_zero_shared();
- return true;
- }
- return false;
- }
- #endif
- - _LIBCPP_HIDE_FROM_ABI long use_count() const _NOEXCEPT { return __libcpp_relaxed_load(&__shared_owners_) + 1; }
- + _LIBCPP_HIDE_FROM_ABI long use_count() const _NOEXCEPT {
- +#ifdef _LIBCPP_HAS_NO_THREADS
- + return __libcpp_relaxed_load(&__shared_owners_) + 1;
- +#else
- + return __shared_owners_.load(memory_order_relaxed) + 1;
- +#endif
- + }
- };
-
- class _LIBCPP_EXPORTED_FROM_ABI __shared_weak_count : private __shared_count {
- - long __shared_weak_owners_;
- +#ifdef _LIBCPP_HAS_NO_THREADS
- + typedef long __atomic_count;
- +#else
- + typedef atomic<long> __atomic_count;
- +#endif
- + __atomic_count __shared_weak_owners_;
-
- public:
- _LIBCPP_HIDE_FROM_ABI explicit __shared_weak_count(long __refs = 0) _NOEXCEPT
- @@ -180,7 +206,13 @@ public:
- void __release_shared() noexcept;
- #else
- _LIBCPP_HIDE_FROM_ABI void __add_shared() _NOEXCEPT { __shared_count::__add_shared(); }
- - _LIBCPP_HIDE_FROM_ABI void __add_weak() _NOEXCEPT { __libcpp_atomic_refcount_increment(__shared_weak_owners_); }
- + _LIBCPP_HIDE_FROM_ABI void __add_weak() _NOEXCEPT {
- +# ifdef _LIBCPP_HAS_NO_THREADS
- + __libcpp_atomic_refcount_increment(__shared_weak_owners_);
- +# else
- + __shared_weak_owners_++;
- +# endif
- + }
- _LIBCPP_HIDE_FROM_ABI void __release_shared() _NOEXCEPT {
- if (__shared_count::__release_shared())
- __release_weak();
|