| Index: runtime/bin/reference_counting.h
|
| diff --git a/runtime/bin/reference_counting.h b/runtime/bin/reference_counting.h
|
| index 8721948de4775be8ea49277d6cd5b855e42e7be1..fb0c3dc8ed2c763b8ee737d7649057324dee8563 100644
|
| --- a/runtime/bin/reference_counting.h
|
| +++ b/runtime/bin/reference_counting.h
|
| @@ -33,32 +33,54 @@ class RefCntReleaseScope;
|
| template <class Derived>
|
| class ReferenceCounted {
|
| public:
|
| - ReferenceCounted() : ref_count_(1) {}
|
| + ReferenceCounted() : ref_count_(1) {
|
| +#if defined(DEBUG)
|
| + AtomicOperations::FetchAndIncrement(&instances_);
|
| +#endif // defined(DEBUG)
|
| + }
|
|
|
| - ~ReferenceCounted() { ASSERT(ref_count_ == 0); }
|
| + virtual ~ReferenceCounted() {
|
| + ASSERT(ref_count_ == 0);
|
| +#if defined(DEBUG)
|
| + AtomicOperations::FetchAndDecrement(&instances_);
|
| +#endif // defined(DEBUG)
|
| + }
|
|
|
| void Retain() {
|
| - uintptr_t old = AtomicOperations::FetchAndIncrement(&ref_count_);
|
| + intptr_t old = AtomicOperations::FetchAndIncrement(&ref_count_);
|
| ASSERT(old > 0);
|
| }
|
|
|
| void Release() {
|
| - uintptr_t old = AtomicOperations::FetchAndDecrement(&ref_count_);
|
| + intptr_t old = AtomicOperations::FetchAndDecrement(&ref_count_);
|
| ASSERT(old > 0);
|
| if (old == 1) {
|
| delete static_cast<Derived*>(this);
|
| }
|
| }
|
|
|
| +#if defined(DEBUG)
|
| + static intptr_t instances() { return instances_; }
|
| +#endif // defined(DEBUG)
|
| +
|
| private:
|
| - uintptr_t ref_count_;
|
| +#if defined(DEBUG)
|
| + static intptr_t instances_;
|
| +#endif // defined(DEBUG)
|
| +
|
| + intptr_t ref_count_;
|
|
|
| // These are used only in the ASSERT below in RefCntReleaseScope.
|
| - uintptr_t ref_count() const { return ref_count_; }
|
| + intptr_t ref_count() const { return ref_count_; }
|
| friend class RefCntReleaseScope<Derived>;
|
| DISALLOW_COPY_AND_ASSIGN(ReferenceCounted);
|
| };
|
|
|
| +#if defined(DEBUG)
|
| +template <class Derived>
|
| +intptr_t ReferenceCounted<Derived>::instances_ = 0;
|
| +#endif
|
| +
|
| // Creates a scope at the end of which a reference counted object is
|
| // Released. This is useful for reference counted objects recieved by the IO
|
| // Service, which have already been Retained E.g.:
|
|
|