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 |
(...skipping 25 matching lines...) Expand all Loading... |
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 SECURITY_DCHECK(m_verifier.onRef(m_refCount)); |
47 DCHECK(!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 SECURITY_DCHECK(m_verifier.isSafeToUse()); |
57 #endif | 57 #endif |
58 return m_refCount == 1; | 58 return m_refCount == 1; |
59 } | 59 } |
60 | 60 |
61 int refCount() const { | 61 int refCount() const { |
62 #if CHECK_REF_COUNTED_LIFECYCLE | 62 #if CHECK_REF_COUNTED_LIFECYCLE |
63 m_verifier.checkSafeToUse(); | 63 SECURITY_DCHECK(m_verifier.isSafeToUse()); |
64 #endif | 64 #endif |
65 return m_refCount; | 65 return m_refCount; |
66 } | 66 } |
67 | 67 |
68 protected: | 68 protected: |
69 RefCountedBase() | 69 RefCountedBase() |
70 : m_refCount(1) | 70 : m_refCount(1) |
71 #if ENABLE(SECURITY_ASSERT) | 71 #if ENABLE(SECURITY_ASSERT) |
72 , | 72 , |
73 m_deletionHasBegun(false) | 73 m_deletionHasBegun(false) |
74 #endif | 74 #endif |
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 DCHECK(!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 SECURITY_DCHECK(m_verifier.onDeref(m_refCount)); |
94 DCHECK(!m_adoptionIsRequired); | 94 DCHECK(!m_adoptionIsRequired); |
95 #endif | 95 #endif |
96 | 96 |
97 DCHECK_GT(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; |
(...skipping 55 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 |