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

Unified Diff: base/memory/ref_counted.h

Issue 2452603002: Modernize ref_counted.h (Closed)
Patch Set: back to PS 2 -- will follow-up with rest Created 4 years, 2 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 20fe49c926de273ded41d6276fd434b1521f2821..f629d5fa8b6da644963ac984f2b486e7b0bb76c7 100644
--- a/base/memory/ref_counted.h
+++ b/base/memory/ref_counted.h
@@ -14,10 +14,8 @@
#include "base/atomic_ref_count.h"
#include "base/base_export.h"
#include "base/compiler_specific.h"
-#include "base/macros.h"
-#ifndef NDEBUG
#include "base/logging.h"
-#endif
+#include "base/macros.h"
#include "base/threading/thread_collision_warner.h"
#include "build/build_config.h"
@@ -32,16 +30,16 @@ class BASE_EXPORT RefCountedBase {
protected:
RefCountedBase()
: ref_count_(0)
- #ifndef NDEBUG
+#if DCHECK_IS_ON()
, in_dtor_(false)
- #endif
+#endif
{
}
~RefCountedBase() {
- #ifndef NDEBUG
+#if DCHECK_IS_ON()
DCHECK(in_dtor_) << "RefCounted object deleted without calling Release()";
- #endif
+#endif
}
@@ -50,9 +48,9 @@ class BASE_EXPORT RefCountedBase {
// Current thread books the critical section "AddRelease"
// without release it.
// DFAKE_SCOPED_LOCK_THREAD_LOCKED(add_release_);
- #ifndef NDEBUG
+#if DCHECK_IS_ON()
DCHECK(!in_dtor_);
- #endif
+#endif
++ref_count_;
}
@@ -62,13 +60,13 @@ class BASE_EXPORT RefCountedBase {
// Current thread books the critical section "AddRelease"
// without release it.
// DFAKE_SCOPED_LOCK_THREAD_LOCKED(add_release_);
- #ifndef NDEBUG
+#if DCHECK_IS_ON()
DCHECK(!in_dtor_);
- #endif
+#endif
if (--ref_count_ == 0) {
- #ifndef NDEBUG
+#if DCHECK_IS_ON()
in_dtor_ = true;
- #endif
+#endif
return true;
}
return false;
@@ -76,7 +74,7 @@ class BASE_EXPORT RefCountedBase {
private:
mutable size_t ref_count_;
-#ifndef NDEBUG
+#if DCHECK_IS_ON()
mutable bool in_dtor_;
#endif
@@ -100,7 +98,7 @@ class BASE_EXPORT RefCountedThreadSafeBase {
private:
mutable AtomicRefCount ref_count_;
-#ifndef NDEBUG
+#if DCHECK_IS_ON()
mutable bool in_dtor_;
#endif
@@ -126,7 +124,7 @@ class BASE_EXPORT RefCountedThreadSafeBase {
template <class T>
class RefCounted : public subtle::RefCountedBase {
public:
- RefCounted() {}
+ RefCounted() = default;
void AddRef() const {
subtle::RefCountedBase::AddRef();
@@ -139,7 +137,7 @@ class RefCounted : public subtle::RefCountedBase {
}
protected:
- ~RefCounted() {}
+ ~RefCounted() = default;
private:
DISALLOW_COPY_AND_ASSIGN(RefCounted<T>);
@@ -176,7 +174,7 @@ struct DefaultRefCountedThreadSafeTraits {
template <class T, typename Traits = DefaultRefCountedThreadSafeTraits<T> >
class RefCountedThreadSafe : public subtle::RefCountedThreadSafeBase {
public:
- RefCountedThreadSafe() {}
+ RefCountedThreadSafe() = default;
void AddRef() const {
subtle::RefCountedThreadSafeBase::AddRef();
@@ -189,7 +187,7 @@ class RefCountedThreadSafe : public subtle::RefCountedThreadSafeBase {
}
protected:
- ~RefCountedThreadSafe() {}
+ ~RefCountedThreadSafe() = default;
private:
friend struct DefaultRefCountedThreadSafeTraits<T>;
@@ -213,7 +211,7 @@ class RefCountedData
private:
friend class base::RefCountedThreadSafe<base::RefCountedData<T> >;
- ~RefCountedData() {}
+ ~RefCountedData() = default;
};
} // namespace base
@@ -237,7 +235,7 @@ class RefCountedData
// void some_other_function() {
// scoped_refptr<MyFoo> foo = new MyFoo();
// ...
-// foo = NULL; // explicitly releases |foo|
+// foo = nullptr; // explicitly releases |foo|
// ...
// if (foo)
// foo->Method(param);
@@ -252,7 +250,7 @@ class RefCountedData
// scoped_refptr<MyFoo> b;
//
// b.swap(a);
-// // now, |b| references the MyFoo object, and |a| references NULL.
+// // now, |b| references the MyFoo object, and |a| references nullptr.
// }
//
// To make both |a| and |b| in the above example reference the same MyFoo
@@ -271,7 +269,7 @@ class scoped_refptr {
public:
typedef T element_type;
- scoped_refptr() : ptr_(NULL) {
+ scoped_refptr() : ptr_(nullptr) {
}
scoped_refptr(T* p) : ptr_(p) {
@@ -314,12 +312,12 @@ class scoped_refptr {
T* get() const { return ptr_; }
T& operator*() const {
- assert(ptr_ != NULL);
+ assert(ptr_ != nullptr);
return *ptr_;
}
T* operator->() const {
- assert(ptr_ != NULL);
+ assert(ptr_ != nullptr);
return ptr_;
}
« 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