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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | base/memory/ref_counted.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef BASE_MEMORY_REF_COUNTED_H_ 5 #ifndef BASE_MEMORY_REF_COUNTED_H_
6 #define BASE_MEMORY_REF_COUNTED_H_ 6 #define BASE_MEMORY_REF_COUNTED_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <cassert> 10 #include <cassert>
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 protected: 135 protected:
136 explicit RefCountedThreadSafeBase(StartRefCountFromZeroTag) {} 136 explicit RefCountedThreadSafeBase(StartRefCountFromZeroTag) {}
137 explicit RefCountedThreadSafeBase(StartRefCountFromOneTag) : ref_count_(1) { 137 explicit RefCountedThreadSafeBase(StartRefCountFromOneTag) : ref_count_(1) {
138 #if DCHECK_IS_ON() 138 #if DCHECK_IS_ON()
139 needs_adopt_ref_ = true; 139 needs_adopt_ref_ = true;
140 #endif 140 #endif
141 } 141 }
142 142
143 ~RefCountedThreadSafeBase(); 143 ~RefCountedThreadSafeBase();
144 144
145 void AddRef() const; 145 void AddRef() const {
146 #if DCHECK_IS_ON()
147 DCHECK(!in_dtor_);
148 DCHECK(!needs_adopt_ref_)
149 << "This RefCounted object is created with non-zero reference count."
150 << " The first reference to such a object has to be made by AdoptRef or"
151 << " MakeRefCounted.";
152 #endif
153 AtomicRefCountInc(&ref_count_);
154 }
146 155
147 // Returns true if the object should self-delete. 156 // Returns true if the object should self-delete.
148 bool Release() const; 157 bool Release() const {
158 #if DCHECK_IS_ON()
159 DCHECK(!in_dtor_);
160 DCHECK(!AtomicRefCountIsZero(&ref_count_));
161 #endif
162 if (!AtomicRefCountDec(&ref_count_)) {
163 #if DCHECK_IS_ON()
164 in_dtor_ = true;
165 #endif
166 return true;
167 }
168 return false;
169 }
149 170
150 private: 171 private:
151 template <typename U> 172 template <typename U>
152 friend scoped_refptr<U> base::AdoptRef(U*); 173 friend scoped_refptr<U> base::AdoptRef(U*);
153 174
154 void Adopted() const { 175 void Adopted() const {
155 #if DCHECK_IS_ON() 176 #if DCHECK_IS_ON()
156 DCHECK(needs_adopt_ref_); 177 DCHECK(needs_adopt_ref_);
157 needs_adopt_ref_ = false; 178 needs_adopt_ref_ = false;
158 #endif 179 #endif
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 bool operator!=(std::nullptr_t null, const scoped_refptr<T>& rhs) { 639 bool operator!=(std::nullptr_t null, const scoped_refptr<T>& rhs) {
619 return !operator==(null, rhs); 640 return !operator==(null, rhs);
620 } 641 }
621 642
622 template <typename T> 643 template <typename T>
623 std::ostream& operator<<(std::ostream& out, const scoped_refptr<T>& p) { 644 std::ostream& operator<<(std::ostream& out, const scoped_refptr<T>& p) {
624 return out << p.get(); 645 return out << p.get();
625 } 646 }
626 647
627 #endif // BASE_MEMORY_REF_COUNTED_H_ 648 #endif // BASE_MEMORY_REF_COUNTED_H_
OLDNEW
« 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