Improved sp_deleter_wrapper implementation

[SVN r44837]
This commit is contained in:
Daniel Frey
2008-04-28 07:17:11 +00:00
parent a01e4c3f83
commit e3422efec6
2 changed files with 11 additions and 17 deletions

View File

@@ -89,10 +89,9 @@ private:
}else if( !_shared_count.empty() ) }else if( !_shared_count.empty() )
{ {
BOOST_ASSERT( owner.unique() ); // no weak_ptrs to owner should exist either, but there's no way to check that BOOST_ASSERT( owner.unique() ); // no weak_ptrs to owner should exist either, but there's no way to check that
typedef detail::sp_deleter_wrapper D; detail::sp_deleter_wrapper * pd = detail::basic_get_deleter<detail::sp_deleter_wrapper>( _shared_count );
D * pd = static_cast<D *>( _shared_count.get_deleter( BOOST_SP_TYPEID(D) ) );
BOOST_ASSERT( pd != 0 ); BOOST_ASSERT( pd != 0 );
pd->set_deleter( owner ); pd->set_deleter( owner.get_shared_count() );
owner.reset( _shared_count, owner.get() ); owner.reset( _shared_count, owner.get() );
detail::shared_count().swap( _shared_count ); detail::shared_count().swap( _shared_count );
} }

View File

@@ -497,11 +497,6 @@ public:
return pn < rhs.pn; return pn < rhs.pn;
} }
void * _internal_get_deleter( detail::sp_typeinfo const & ti ) const
{
return pn.get_deleter( ti );
}
// atomic access // atomic access
#if !defined(BOOST_SP_NO_ATOMIC_ACCESS) #if !defined(BOOST_SP_NO_ATOMIC_ACCESS)
@@ -701,35 +696,35 @@ namespace detail
// g++ 2.9x doesn't allow static_cast<X const *>(void *) // g++ 2.9x doesn't allow static_cast<X const *>(void *)
// apparently EDG 2.38 and HP aCC A.03.35 also don't accept it // apparently EDG 2.38 and HP aCC A.03.35 also don't accept it
template<class D, class T> D * basic_get_deleter(shared_ptr<T> const & p) template<class D> D * basic_get_deleter(shared_count const & c)
{ {
void const * q = p._internal_get_deleter(BOOST_SP_TYPEID(D)); void const * q = c.get_deleter(BOOST_SP_TYPEID(D));
return const_cast<D *>(static_cast<D const *>(q)); return const_cast<D *>(static_cast<D const *>(q));
} }
#else #else
template<class D, class T> D * basic_get_deleter(shared_ptr<T> const & p) template<class D> D * basic_get_deleter(shared_count const & c)
{ {
return static_cast<D *>(p._internal_get_deleter(BOOST_SP_TYPEID(D))); return static_cast<D *>(c.get_deleter(BOOST_SP_TYPEID(D)));
} }
#endif #endif
class sp_deleter_wrapper class sp_deleter_wrapper
{ {
shared_ptr<const void> _deleter; detail::shared_count _deleter;
public: public:
sp_deleter_wrapper() sp_deleter_wrapper()
{} {}
void set_deleter(const shared_ptr<const void> &deleter) void set_deleter(shared_count const &deleter)
{ {
_deleter = deleter; _deleter = deleter;
} }
void operator()(const void *) void operator()(const void *)
{ {
BOOST_ASSERT(_deleter.use_count() <= 1); BOOST_ASSERT(_deleter.use_count() <= 1);
_deleter.reset(); detail::shared_count().swap( _deleter );
} }
template<typename D> template<typename D>
D* get_deleter() const D* get_deleter() const
@@ -742,10 +737,10 @@ public:
template<class D, class T> D * get_deleter(shared_ptr<T> const & p) template<class D, class T> D * get_deleter(shared_ptr<T> const & p)
{ {
D *del = detail::basic_get_deleter<D>(p); D *del = detail::basic_get_deleter<D>(p.get_shared_count());
if(del == 0) if(del == 0)
{ {
detail::sp_deleter_wrapper *del_wrapper = detail::basic_get_deleter<detail::sp_deleter_wrapper>(p); detail::sp_deleter_wrapper *del_wrapper = detail::basic_get_deleter<detail::sp_deleter_wrapper>(p.get_shared_count());
// The following get_deleter method call is fully qualified because // The following get_deleter method call is fully qualified because
// older versions of gcc (2.95, 3.2.3) fail to compile it when written del_wrapper->get_deleter<D>() // older versions of gcc (2.95, 3.2.3) fail to compile it when written del_wrapper->get_deleter<D>()
if(del_wrapper) del = del_wrapper->::boost::detail::sp_deleter_wrapper::get_deleter<D>(); if(del_wrapper) del = del_wrapper->::boost::detail::sp_deleter_wrapper::get_deleter<D>();