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

Unified Diff: base/memory/ref_counted.h

Issue 2345013003: Remove ref_counted.cc (Closed)
Patch Set: revert _EXPORT part Created 4 years, 3 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 | « base/BUILD.gn ('k') | 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 05fc4c4d3ff76e3554fbbbeff37b5d2856a9f242..16e993a230a6904aeba73aca404283a0a8765357 100644
--- a/base/memory/ref_counted.h
+++ b/base/memory/ref_counted.h
@@ -87,16 +87,46 @@ class BASE_EXPORT RefCountedBase {
class BASE_EXPORT RefCountedThreadSafeBase {
public:
- bool HasOneRef() const;
+ bool HasOneRef() const {
+ return AtomicRefCountIsOne(
+ &const_cast<RefCountedThreadSafeBase*>(this)->ref_count_);
+ }
protected:
- RefCountedThreadSafeBase();
- ~RefCountedThreadSafeBase();
+ RefCountedThreadSafeBase() : ref_count_(0) {
+#ifndef NDEBUG
+ in_dtor_ = false;
+#endif
+ }
+
+ ~RefCountedThreadSafeBase() {
+#ifndef NDEBUG
+ DCHECK(in_dtor_) << "RefCountedThreadSafe object deleted without "
+ "calling Release()";
+#endif
+ }
- void AddRef() const;
+ void AddRef() const {
+#ifndef NDEBUG
+ DCHECK(!in_dtor_);
+#endif
+ AtomicRefCountInc(&ref_count_);
+ }
// Returns true if the object should self-delete.
- bool Release() const;
+ bool Release() const {
+#ifndef NDEBUG
+ DCHECK(!in_dtor_);
+ DCHECK(!AtomicRefCountIsZero(&ref_count_));
+#endif
+ if (!AtomicRefCountDec(&ref_count_)) {
+#ifndef NDEBUG
+ in_dtor_ = true;
+#endif
+ return true;
+ }
+ return false;
+ }
private:
mutable AtomicRefCount ref_count_;
« no previous file with comments | « base/BUILD.gn ('k') | base/memory/ref_counted.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698