From 951c2b7e833146f20023b0609c67d2689f446f16 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Thu, 20 Jun 2002 14:56:10 +0000 Subject: [PATCH] counted_base is now smaller [SVN r14212] --- include/boost/detail/shared_count.hpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/include/boost/detail/shared_count.hpp b/include/boost/detail/shared_count.hpp index 63316f4..cc325ea 100644 --- a/include/boost/detail/shared_count.hpp +++ b/include/boost/detail/shared_count.hpp @@ -50,14 +50,14 @@ private: public: counted_base(): - use_count_(0), weak_count_(0), self_deleter_(&self_delete) + use_count_(0), weak_count_(0) { } // pre: initial_use_count <= initial_weak_count explicit counted_base(long initial_use_count, long initial_weak_count): - use_count_(initial_use_count), weak_count_(initial_weak_count), self_deleter_(&self_delete) + use_count_(initial_use_count), weak_count_(initial_weak_count) { } @@ -78,6 +78,13 @@ public: { } + // destruct() is called when weak_count_ drops to zero. + + virtual void destruct() // nothrow + { + delete this; + } + void add_ref() { #ifdef BOOST_HAS_THREADS @@ -108,9 +115,7 @@ public: if(new_weak_count == 0) { - // not a direct 'delete this', because the inlined - // release() may use a different heap manager - self_deleter_(this); + destruct(); } } @@ -135,7 +140,7 @@ public: if(new_weak_count == 0) { - self_deleter_(this); + destruct(); } } @@ -152,19 +157,14 @@ private: counted_base(counted_base const &); counted_base & operator= (counted_base const &); - static void self_delete(counted_base * p) - { - delete p; - } - // inv: use_count_ <= weak_count_ long use_count_; long weak_count_; + #ifdef BOOST_HAS_THREADS mutable mutex_type mtx_; #endif - void (*self_deleter_) (counted_base *); }; inline void intrusive_ptr_add_ref(counted_base * p)