OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
5 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public |
6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
8 * | 8 * |
9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 * Library General Public License for more details. | 12 * Library General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU Library General Public License | 14 * You should have received a copy of the GNU Library General Public License |
15 * along with this library; see the file COPYING.LIB. If not, write to | 15 * along with this library; see the file COPYING.LIB. If not, write to |
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
17 * Boston, MA 02110-1301, USA. | 17 * Boston, MA 02110-1301, USA. |
18 * | 18 * |
19 */ | 19 */ |
20 | 20 |
21 #ifndef RefCounted_h | 21 #ifndef RefCounted_h |
22 #define RefCounted_h | 22 #define RefCounted_h |
23 | 23 |
24 #include "wtf/Allocator.h" | 24 #include "wtf/Allocator.h" |
25 #include "wtf/Assertions.h" | 25 #include "wtf/Assertions.h" |
26 #include "wtf/InstanceCounter.h" | 26 #include "wtf/InstanceCounter.h" |
27 #include "wtf/Noncopyable.h" | 27 #include "wtf/Noncopyable.h" |
28 #include "wtf/WTFExport.h" | 28 #include "wtf/WTFExport.h" |
29 | 29 |
30 #if ENABLE(ASSERT) | 30 #if DCHECK_IS_ON() |
31 #define CHECK_REF_COUNTED_LIFECYCLE 1 | 31 #define CHECK_REF_COUNTED_LIFECYCLE 1 |
32 #include "wtf/ThreadRestrictionVerifier.h" | 32 #include "wtf/ThreadRestrictionVerifier.h" |
33 #else | 33 #else |
34 #define CHECK_REF_COUNTED_LIFECYCLE 0 | 34 #define CHECK_REF_COUNTED_LIFECYCLE 0 |
35 #endif | 35 #endif |
36 | 36 |
37 namespace WTF { | 37 namespace WTF { |
38 | 38 |
39 // This base class holds the non-template methods and attributes. | 39 // This base class holds the non-template methods and attributes. |
40 // The RefCounted class inherits from it reducing the template bloat | 40 // The RefCounted class inherits from it reducing the template bloat |
41 // generated by the compiler (technique called template hoisting). | 41 // generated by the compiler (technique called template hoisting). |
42 class WTF_EXPORT RefCountedBase { | 42 class WTF_EXPORT RefCountedBase { |
43 public: | 43 public: |
44 void ref() const { | 44 void ref() const { |
45 #if CHECK_REF_COUNTED_LIFECYCLE | 45 #if CHECK_REF_COUNTED_LIFECYCLE |
46 m_verifier.onRef(m_refCount); | 46 m_verifier.onRef(m_refCount); |
47 ASSERT(!m_adoptionIsRequired); | 47 DCHECK(!m_adoptionIsRequired); |
48 #endif | 48 #endif |
49 SECURITY_DCHECK(!m_deletionHasBegun); | 49 SECURITY_DCHECK(!m_deletionHasBegun); |
50 ++m_refCount; | 50 ++m_refCount; |
51 } | 51 } |
52 | 52 |
53 bool hasOneRef() const { | 53 bool hasOneRef() const { |
54 SECURITY_DCHECK(!m_deletionHasBegun); | 54 SECURITY_DCHECK(!m_deletionHasBegun); |
55 #if CHECK_REF_COUNTED_LIFECYCLE | 55 #if CHECK_REF_COUNTED_LIFECYCLE |
56 m_verifier.checkSafeToUse(); | 56 m_verifier.checkSafeToUse(); |
57 #endif | 57 #endif |
(...skipping 17 matching lines...) Expand all Loading... |
75 #if CHECK_REF_COUNTED_LIFECYCLE | 75 #if CHECK_REF_COUNTED_LIFECYCLE |
76 , | 76 , |
77 m_adoptionIsRequired(true) | 77 m_adoptionIsRequired(true) |
78 #endif | 78 #endif |
79 { | 79 { |
80 } | 80 } |
81 | 81 |
82 ~RefCountedBase() { | 82 ~RefCountedBase() { |
83 SECURITY_DCHECK(m_deletionHasBegun); | 83 SECURITY_DCHECK(m_deletionHasBegun); |
84 #if CHECK_REF_COUNTED_LIFECYCLE | 84 #if CHECK_REF_COUNTED_LIFECYCLE |
85 ASSERT(!m_adoptionIsRequired); | 85 DCHECK(!m_adoptionIsRequired); |
86 #endif | 86 #endif |
87 } | 87 } |
88 | 88 |
89 // Returns whether the pointer should be freed or not. | 89 // Returns whether the pointer should be freed or not. |
90 bool derefBase() const { | 90 bool derefBase() const { |
91 SECURITY_DCHECK(!m_deletionHasBegun); | 91 SECURITY_DCHECK(!m_deletionHasBegun); |
92 #if CHECK_REF_COUNTED_LIFECYCLE | 92 #if CHECK_REF_COUNTED_LIFECYCLE |
93 m_verifier.onDeref(m_refCount); | 93 m_verifier.onDeref(m_refCount); |
94 ASSERT(!m_adoptionIsRequired); | 94 DCHECK(!m_adoptionIsRequired); |
95 #endif | 95 #endif |
96 | 96 |
97 ASSERT(m_refCount > 0); | 97 DCHECK_GT(m_refCount, 0); |
98 --m_refCount; | 98 --m_refCount; |
99 if (!m_refCount) { | 99 if (!m_refCount) { |
100 #if ENABLE(SECURITY_ASSERT) | 100 #if ENABLE(SECURITY_ASSERT) |
101 m_deletionHasBegun = true; | 101 m_deletionHasBegun = true; |
102 #endif | 102 #endif |
103 return true; | 103 return true; |
104 } | 104 } |
105 | 105 |
106 return false; | 106 return false; |
107 } | 107 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 #else | 159 #else |
160 RefCounted() {} | 160 RefCounted() {} |
161 #endif | 161 #endif |
162 }; | 162 }; |
163 | 163 |
164 } // namespace WTF | 164 } // namespace WTF |
165 | 165 |
166 using WTF::RefCounted; | 166 using WTF::RefCounted; |
167 | 167 |
168 #endif // RefCounted_h | 168 #endif // RefCounted_h |
OLD | NEW |