@@ -22,37 +22,10 @@ _LIBCPP_BEGIN_NAMESPACE_STD
22
22
// NOTE: Relaxed and acq/rel atomics (for increment and decrement respectively)
23
23
// should be sufficient for thread safety.
24
24
// See https://llvm.org/PR22803
25
- #if (defined(__clang__) && __has_builtin(__atomic_add_fetch) && defined(__ATOMIC_RELAXED) && \
26
- defined (__ATOMIC_ACQ_REL)) || \
27
- defined(_LIBCPP_COMPILER_GCC)
28
- # define _LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT 1
29
- #else
30
- # define _LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT 0
31
- #endif
32
-
33
- template <class _ValueType >
34
- inline _LIBCPP_HIDE_FROM_ABI _ValueType __libcpp_relaxed_load (_ValueType const * __value) {
35
- #if _LIBCPP_HAS_THREADS && defined(__ATOMIC_RELAXED) && \
36
- (__has_builtin (__atomic_load_n) || defined (_LIBCPP_COMPILER_GCC))
37
- return __atomic_load_n (__value, __ATOMIC_RELAXED);
38
- #else
39
- return *__value;
40
- #endif
41
- }
42
-
43
- template <class _ValueType >
44
- inline _LIBCPP_HIDE_FROM_ABI _ValueType __libcpp_acquire_load (_ValueType const * __value) {
45
- #if _LIBCPP_HAS_THREADS && defined(__ATOMIC_ACQUIRE) && \
46
- (__has_builtin (__atomic_load_n) || defined (_LIBCPP_COMPILER_GCC))
47
- return __atomic_load_n (__value, __ATOMIC_ACQUIRE);
48
- #else
49
- return *__value;
50
- #endif
51
- }
52
25
53
26
template <class _Tp >
54
27
inline _LIBCPP_HIDE_FROM_ABI _Tp __libcpp_atomic_refcount_increment (_Tp& __t ) _NOEXCEPT {
55
- #if _LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT && _LIBCPP_HAS_THREADS
28
+ #if _LIBCPP_HAS_THREADS
56
29
return __atomic_add_fetch (std::addressof (__t ), 1 , __ATOMIC_RELAXED);
57
30
#else
58
31
return __t += 1 ;
@@ -61,7 +34,7 @@ inline _LIBCPP_HIDE_FROM_ABI _Tp __libcpp_atomic_refcount_increment(_Tp& __t) _N
61
34
62
35
template <class _Tp >
63
36
inline _LIBCPP_HIDE_FROM_ABI _Tp __libcpp_atomic_refcount_decrement (_Tp& __t ) _NOEXCEPT {
64
- #if _LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT && _LIBCPP_HAS_THREADS
37
+ #if _LIBCPP_HAS_THREADS
65
38
return __atomic_add_fetch (std::addressof (__t ), -1 , __ATOMIC_ACQ_REL);
66
39
#else
67
40
return __t -= 1 ;
@@ -95,7 +68,13 @@ class _LIBCPP_EXPORTED_FROM_ABI __shared_count {
95
68
return false ;
96
69
}
97
70
#endif
98
- _LIBCPP_HIDE_FROM_ABI long use_count () const _NOEXCEPT { return __libcpp_relaxed_load (&__shared_owners_) + 1 ; }
71
+ _LIBCPP_HIDE_FROM_ABI long use_count () const _NOEXCEPT {
72
+ #if _LIBCPP_HAS_THREADS
73
+ return __atomic_load_n (&__shared_owners_, __ATOMIC_RELAXED) + 1 ;
74
+ #else
75
+ return __value + 1 ;
76
+ #endif
77
+ }
99
78
};
100
79
101
80
class _LIBCPP_EXPORTED_FROM_ABI __shared_weak_count : private __shared_count {
0 commit comments