| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/thread_collision_warner.h" | |
| 9 | 8 |
| 10 namespace base { | 9 namespace base { |
| 11 | 10 |
| 12 namespace subtle { | 11 namespace subtle { |
| 13 | 12 |
| 14 RefCountedBase::RefCountedBase() : ref_count_(0) { | 13 RefCountedBase::RefCountedBase() : ref_count_(0) { |
| 15 #ifndef NDEBUG | 14 #ifndef NDEBUG |
| 16 in_dtor_ = false; | 15 in_dtor_ = false; |
| 17 #endif | 16 #endif |
| 18 } | 17 } |
| 19 | 18 |
| 20 RefCountedBase::~RefCountedBase() { | 19 RefCountedBase::~RefCountedBase() { |
| 21 #ifndef NDEBUG | 20 #ifndef NDEBUG |
| 22 DCHECK(in_dtor_) << "RefCounted object deleted without calling Release()"; | 21 DCHECK(in_dtor_) << "RefCounted object deleted without calling Release()"; |
| 23 #endif | 22 #endif |
| 24 } | 23 } |
| 25 | 24 |
| 26 void RefCountedBase::AddRef() { | 25 void RefCountedBase::AddRef() { |
| 27 // TODO(maruel): Add back once it doesn't assert 500 times/sec. | |
| 28 // Current thread books the critical section "AddRelease" without release it. | |
| 29 // DFAKE_SCOPED_LOCK_THREAD_LOCKED(add_release_); | |
| 30 #ifndef NDEBUG | 26 #ifndef NDEBUG |
| 31 DCHECK(!in_dtor_); | 27 DCHECK(!in_dtor_); |
| 32 #endif | 28 #endif |
| 33 ++ref_count_; | 29 ++ref_count_; |
| 34 } | 30 } |
| 35 | 31 |
| 36 bool RefCountedBase::Release() { | 32 bool RefCountedBase::Release() { |
| 37 // TODO(maruel): Add back once it doesn't assert 500 times/sec. | |
| 38 // Current thread books the critical section "AddRelease" without release it. | |
| 39 // DFAKE_SCOPED_LOCK_THREAD_LOCKED(add_release_); | |
| 40 #ifndef NDEBUG | 33 #ifndef NDEBUG |
| 41 DCHECK(!in_dtor_); | 34 DCHECK(!in_dtor_); |
| 42 #endif | 35 #endif |
| 43 if (--ref_count_ == 0) { | 36 if (--ref_count_ == 0) { |
| 44 #ifndef NDEBUG | 37 #ifndef NDEBUG |
| 45 in_dtor_ = true; | 38 in_dtor_ = true; |
| 46 #endif | 39 #endif |
| 47 return true; | 40 return true; |
| 48 } | 41 } |
| 49 return false; | 42 return false; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 80 #endif | 73 #endif |
| 81 return true; | 74 return true; |
| 82 } | 75 } |
| 83 return false; | 76 return false; |
| 84 } | 77 } |
| 85 | 78 |
| 86 } // namespace subtle | 79 } // namespace subtle |
| 87 | 80 |
| 88 } // namespace base | 81 } // namespace base |
| 89 | 82 |
| OLD | NEW |