52 _GLIBCXX_BEGIN_NAMESPACE_TR1
54 class bad_weak_ptr :
public std::exception
59 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
60 {
return "std::bad_weak_ptr"; }
62 {
return "tr1::bad_weak_ptr"; }
68 __throw_bad_weak_ptr()
77 using __gnu_cxx::_Lock_policy;
78 using __gnu_cxx::__default_lock_policy;
79 using __gnu_cxx::_S_single;
80 using __gnu_cxx::_S_mutex;
81 using __gnu_cxx::_S_atomic;
84 template<_Lock_policy _Lp>
89 enum { _S_need_barriers = 0 };
93 class _Mutex_base<_S_mutex>
94 :
public __gnu_cxx::__mutex
100 enum { _S_need_barriers = 1 };
103 template<_Lock_policy _Lp = __default_lock_policy>
104 class _Sp_counted_base
105 :
public _Mutex_base<_Lp>
109 : _M_use_count(1), _M_weak_count(1) { }
126 _M_get_deleter(
const std::type_info&) = 0;
130 { __gnu_cxx::__atomic_add_dispatch(&_M_use_count, 1); }
138 if (__gnu_cxx::__exchange_and_add_dispatch(&_M_use_count, -1) == 1)
145 if (_Mutex_base<_Lp>::_S_need_barriers)
147 _GLIBCXX_READ_MEM_BARRIER;
148 _GLIBCXX_WRITE_MEM_BARRIER;
151 if (__gnu_cxx::__exchange_and_add_dispatch(&_M_weak_count,
159 { __gnu_cxx::__atomic_add_dispatch(&_M_weak_count, 1); }
164 if (__gnu_cxx::__exchange_and_add_dispatch(&_M_weak_count, -1) == 1)
166 if (_Mutex_base<_Lp>::_S_need_barriers)
170 _GLIBCXX_READ_MEM_BARRIER;
171 _GLIBCXX_WRITE_MEM_BARRIER;
178 _M_get_use_count() const
182 return const_cast<const volatile _Atomic_word&
>(_M_use_count);
186 _Sp_counted_base(_Sp_counted_base
const&);
187 _Sp_counted_base& operator=(_Sp_counted_base
const&);
189 _Atomic_word _M_use_count;
190 _Atomic_word _M_weak_count;
195 _Sp_counted_base<_S_single>::
198 if (__gnu_cxx::__exchange_and_add_dispatch(&_M_use_count, 1) == 0)
201 __throw_bad_weak_ptr();
207 _Sp_counted_base<_S_mutex>::
211 if (__gnu_cxx::__exchange_and_add_dispatch(&_M_use_count, 1) == 0)
214 __throw_bad_weak_ptr();
220 _Sp_counted_base<_S_atomic>::
224 _Atomic_word __count;
227 __count = _M_use_count;
229 __throw_bad_weak_ptr();
234 while (!__sync_bool_compare_and_swap(&_M_use_count, __count,
238 _GLIBCXX_END_NAMESPACE_TR1
ISO C++ entities toplevel namespace is std.