--------------------- PatchSet 454 Date: 2002/12/21 13:06:08 Author: rbcollins Branch: esi Tag: (none) Log: debug refcounting when needed Members: include/RefCount.h:1.1.4.3->1.1.4.4 Index: squid3/include/RefCount.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/include/RefCount.h,v retrieving revision 1.1.4.3 retrieving revision 1.1.4.4 diff -u -r1.1.4.3 -r1.1.4.4 --- squid3/include/RefCount.h 19 Dec 2002 11:25:49 -0000 1.1.4.3 +++ squid3/include/RefCount.h 21 Dec 2002 13:06:08 -0000 1.1.4.4 @@ -1,6 +1,6 @@ /* - * $Id: RefCount.h,v 1.1.4.3 2002/12/19 11:25:49 rbcollins Exp $ + * $Id: RefCount.h,v 1.1.4.4 2002/12/21 13:06:08 rbcollins Exp $ * * DEBUG: section xx Refcount allocator * AUTHOR: Robert Collins @@ -40,7 +40,7 @@ class RefCount { public: RefCount () : p_ (NULL) {} - RefCount (C const *p) : p_(p) { if (p_) p_->RefCountReference(); } + RefCount (C const *p) : p_(p) { reference (*this); } ~RefCount() { dereference(); @@ -72,6 +72,7 @@ void dereference() { if (p_ && p_->RefCountDereference() == 0) p_->deleteSelf(); + p_ = NULL; } void reference (const RefCount& p) { @@ -87,8 +88,17 @@ virtual ~RefCountable_(){} virtual void deleteSelf() const = 0; /* Not private, to allow class hierarchies */ - void RefCountReference() const { ++count_; } - unsigned RefCountDereference() const { return --count_; } + void RefCountReference() const { +#if REFCOUNT_DEBUG + debug (0,1)("Incrementing this %p from count %u\n",this,count_); +#endif + ++count_; } + unsigned RefCountDereference() const { +#if REFCOUNT_DEBUG + debug (0,1)("Decrementing this %p from count %u\n",this,count_); +#endif + return --count_; + } private: mutable unsigned count_; };