shared_ptr::lock no longer requires exceptions.

[SVN r44344]
This commit is contained in:
Peter Dimov
2008-04-12 14:27:22 +00:00
parent dbd62686a3
commit f85a1bf406
3 changed files with 29 additions and 25 deletions
+1 -25
View File
@@ -93,31 +93,7 @@ public:
shared_ptr<T> lock() const // never throws
{
#if defined(BOOST_HAS_THREADS)
// optimization: avoid throw overhead
if(expired())
{
return shared_ptr<element_type>();
}
try
{
return shared_ptr<element_type>(*this);
}
catch(bad_weak_ptr const &)
{
// Q: how can we get here?
// A: another thread may have invalidated r after the use_count test above.
return shared_ptr<element_type>();
}
#else
// optimization: avoid try/catch overhead when single threaded
return expired()? shared_ptr<element_type>(): shared_ptr<element_type>(*this);
#endif
return shared_ptr<element_type>( *this, boost::detail::sp_nothrow_tag() );
}
long use_count() const // never throws