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

Unified Diff: base/memory/ref_counted.h

Issue 2947863003: Make RefCountedThreadSafeBase::AddRef and Release available for inlining (Closed)
Patch Set: Created 3 years, 6 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 | base/memory/ref_counted.cc » ('j') | 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 6c363ccd709b71d1be8a8494f73c4b1f6c2f4a43..3695f87b080f086cb961810eae232d67e12ec34c 100644
--- a/base/memory/ref_counted.h
+++ b/base/memory/ref_counted.h
@@ -142,10 +142,31 @@ class BASE_EXPORT RefCountedThreadSafeBase {
~RefCountedThreadSafeBase();
- void AddRef() const;
+ void AddRef() const {
+#if DCHECK_IS_ON()
+ DCHECK(!in_dtor_);
+ DCHECK(!needs_adopt_ref_)
+ << "This RefCounted object is created with non-zero reference count."
+ << " The first reference to such a object has to be made by AdoptRef or"
+ << " MakeRefCounted.";
+#endif
+ AtomicRefCountInc(&ref_count_);
+ }
// Returns true if the object should self-delete.
- bool Release() const;
+ bool Release() const {
+#if DCHECK_IS_ON()
+ DCHECK(!in_dtor_);
+ DCHECK(!AtomicRefCountIsZero(&ref_count_));
+#endif
+ if (!AtomicRefCountDec(&ref_count_)) {
+#if DCHECK_IS_ON()
+ in_dtor_ = true;
+#endif
+ return true;
+ }
+ return false;
+ }
private:
template <typename U>
« no previous file with comments | « no previous file | base/memory/ref_counted.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698