Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(522)

Unified Diff: runtime/bin/reference_counting.h

Issue 2760293002: [dart:io] Adds a finalizer to _NativeSocket to avoid socket leaks (Closed)
Patch Set: Address comments Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/bin/process_win.cc ('k') | runtime/bin/socket.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.:
« no previous file with comments | « runtime/bin/process_win.cc ('k') | runtime/bin/socket.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698