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

Unified Diff: base/memory/ref_counted.h

Issue 2789463002: Clean up around RefCountedBase (Closed)
Patch Set: rebase 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/memory/ref_counted.h
diff --git a/base/memory/ref_counted.h b/base/memory/ref_counted.h
index 37012de0a6bcd3a548db9c4f5c1fe19c26582fef..503a86a45f02bd5d65c7ad0a2c6912a923eba0d7 100644
--- a/base/memory/ref_counted.h
+++ b/base/memory/ref_counted.h
@@ -28,13 +28,7 @@ class BASE_EXPORT RefCountedBase {
bool HasOneRef() const { return ref_count_ == 1; }
protected:
- RefCountedBase()
- : ref_count_(0)
-#if DCHECK_IS_ON()
- , in_dtor_(false)
-#endif
- {
- }
+ RefCountedBase() {}
~RefCountedBase() {
#if DCHECK_IS_ON()
@@ -42,7 +36,6 @@ class BASE_EXPORT RefCountedBase {
#endif
}
-
void AddRef() const {
// TODO(maruel): Add back once it doesn't assert 500 times/sec.
// Current thread books the critical section "AddRelease"
@@ -51,31 +44,32 @@ class BASE_EXPORT RefCountedBase {
#if DCHECK_IS_ON()
DCHECK(!in_dtor_);
#endif
+
++ref_count_;
}
// Returns true if the object should self-delete.
bool Release() const {
+ --ref_count_;
+
// TODO(maruel): Add back once it doesn't assert 500 times/sec.
// Current thread books the critical section "AddRelease"
// without release it.
// DFAKE_SCOPED_LOCK_THREAD_LOCKED(add_release_);
+
#if DCHECK_IS_ON()
DCHECK(!in_dtor_);
-#endif
- if (--ref_count_ == 0) {
-#if DCHECK_IS_ON()
+ if (ref_count_ == 0)
in_dtor_ = true;
#endif
- return true;
- }
- return false;
+
+ return ref_count_ == 0;
}
private:
- mutable size_t ref_count_;
+ mutable size_t ref_count_ = 0;
#if DCHECK_IS_ON()
- mutable bool in_dtor_;
+ mutable bool in_dtor_ = false;
#endif
DFAKE_MUTEX(add_release_);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698