OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include "base/ref_counted.h" | 5 #include "base/ref_counted.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/threading/thread_collision_warner.h" | 8 #include "base/threading/thread_collision_warner.h" |
9 | 9 |
10 namespace base { | 10 namespace base { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 #endif | 44 #endif |
45 if (--ref_count_ == 0) { | 45 if (--ref_count_ == 0) { |
46 #ifndef NDEBUG | 46 #ifndef NDEBUG |
47 in_dtor_ = true; | 47 in_dtor_ = true; |
48 #endif | 48 #endif |
49 return true; | 49 return true; |
50 } | 50 } |
51 return false; | 51 return false; |
52 } | 52 } |
53 | 53 |
| 54 bool RefCountedThreadSafeBase::HasOneRef() const { |
| 55 return AtomicRefCountIsOne( |
| 56 &const_cast<RefCountedThreadSafeBase*>(this)->ref_count_); |
| 57 } |
| 58 |
54 RefCountedThreadSafeBase::RefCountedThreadSafeBase() : ref_count_(0) { | 59 RefCountedThreadSafeBase::RefCountedThreadSafeBase() : ref_count_(0) { |
55 #ifndef NDEBUG | 60 #ifndef NDEBUG |
56 in_dtor_ = false; | 61 in_dtor_ = false; |
57 #endif | 62 #endif |
58 } | 63 } |
59 | 64 |
60 RefCountedThreadSafeBase::~RefCountedThreadSafeBase() { | 65 RefCountedThreadSafeBase::~RefCountedThreadSafeBase() { |
61 #ifndef NDEBUG | 66 #ifndef NDEBUG |
62 DCHECK(in_dtor_) << "RefCountedThreadSafe object deleted without " | 67 DCHECK(in_dtor_) << "RefCountedThreadSafe object deleted without " |
63 "calling Release()"; | 68 "calling Release()"; |
(...skipping 14 matching lines...) Expand all Loading... |
78 #endif | 83 #endif |
79 if (!AtomicRefCountDec(&ref_count_)) { | 84 if (!AtomicRefCountDec(&ref_count_)) { |
80 #ifndef NDEBUG | 85 #ifndef NDEBUG |
81 in_dtor_ = true; | 86 in_dtor_ = true; |
82 #endif | 87 #endif |
83 return true; | 88 return true; |
84 } | 89 } |
85 return false; | 90 return false; |
86 } | 91 } |
87 | 92 |
88 bool RefCountedThreadSafeBase::HasOneRef() const { | |
89 return AtomicRefCountIsOne( | |
90 &const_cast<RefCountedThreadSafeBase*>(this)->ref_count_); | |
91 } | |
92 | |
93 } // namespace subtle | 93 } // namespace subtle |
94 | 94 |
95 } // namespace base | 95 } // namespace base |
OLD | NEW |