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" |
8 | 9 |
9 namespace base { | 10 namespace base { |
10 | 11 |
11 namespace subtle { | 12 namespace subtle { |
12 | 13 |
13 RefCountedBase::RefCountedBase() : ref_count_(0) { | 14 RefCountedBase::RefCountedBase() : ref_count_(0) { |
14 #ifndef NDEBUG | 15 #ifndef NDEBUG |
15 in_dtor_ = false; | 16 in_dtor_ = false; |
16 #endif | 17 #endif |
17 } | 18 } |
18 | 19 |
19 RefCountedBase::~RefCountedBase() { | 20 RefCountedBase::~RefCountedBase() { |
20 #ifndef NDEBUG | 21 #ifndef NDEBUG |
21 DCHECK(in_dtor_) << "RefCounted object deleted without calling Release()"; | 22 DCHECK(in_dtor_) << "RefCounted object deleted without calling Release()"; |
22 #endif | 23 #endif |
23 } | 24 } |
24 | 25 |
25 void RefCountedBase::AddRef() { | 26 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_); |
26 #ifndef NDEBUG | 30 #ifndef NDEBUG |
27 DCHECK(!in_dtor_); | 31 DCHECK(!in_dtor_); |
28 #endif | 32 #endif |
29 ++ref_count_; | 33 ++ref_count_; |
30 } | 34 } |
31 | 35 |
32 bool RefCountedBase::Release() { | 36 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_); |
33 #ifndef NDEBUG | 40 #ifndef NDEBUG |
34 DCHECK(!in_dtor_); | 41 DCHECK(!in_dtor_); |
35 #endif | 42 #endif |
36 if (--ref_count_ == 0) { | 43 if (--ref_count_ == 0) { |
37 #ifndef NDEBUG | 44 #ifndef NDEBUG |
38 in_dtor_ = true; | 45 in_dtor_ = true; |
39 #endif | 46 #endif |
40 return true; | 47 return true; |
41 } | 48 } |
42 return false; | 49 return false; |
(...skipping 30 matching lines...) Expand all Loading... |
73 #endif | 80 #endif |
74 return true; | 81 return true; |
75 } | 82 } |
76 return false; | 83 return false; |
77 } | 84 } |
78 | 85 |
79 } // namespace subtle | 86 } // namespace subtle |
80 | 87 |
81 } // namespace base | 88 } // namespace base |
82 | 89 |
OLD | NEW |