| 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 { | 75 { |
| 76 #if CHECK_REF_COUNTED_LIFECYCLE | 76 #if CHECK_REF_COUNTED_LIFECYCLE |
| 77 ASSERT(m_verifier.isSafeToUse()); | 77 ASSERT(m_verifier.isSafeToUse()); |
| 78 #endif | 78 #endif |
| 79 return m_refCount; | 79 return m_refCount; |
| 80 } | 80 } |
| 81 | 81 |
| 82 protected: | 82 protected: |
| 83 RefCountedBase() | 83 RefCountedBase() |
| 84 : m_refCount(1) | 84 : m_refCount(1) |
| 85 #if SECURITY_ASSERT_ENABLED | 85 #if ENABLE(SECURITY_ASSERT) |
| 86 , m_deletionHasBegun(false) | 86 , m_deletionHasBegun(false) |
| 87 #endif | 87 #endif |
| 88 #if CHECK_REF_COUNTED_LIFECYCLE | 88 #if CHECK_REF_COUNTED_LIFECYCLE |
| 89 , m_adoptionIsRequired(true) | 89 , m_adoptionIsRequired(true) |
| 90 #endif | 90 #endif |
| 91 { | 91 { |
| 92 } | 92 } |
| 93 | 93 |
| 94 ~RefCountedBase() | 94 ~RefCountedBase() |
| 95 { | 95 { |
| 96 ASSERT_WITH_SECURITY_IMPLICATION(m_deletionHasBegun); | 96 ASSERT_WITH_SECURITY_IMPLICATION(m_deletionHasBegun); |
| 97 #if CHECK_REF_COUNTED_LIFECYCLE | 97 #if CHECK_REF_COUNTED_LIFECYCLE |
| 98 ASSERT(!m_adoptionIsRequired); | 98 ASSERT(!m_adoptionIsRequired); |
| 99 #endif | 99 #endif |
| 100 } | 100 } |
| 101 | 101 |
| 102 // Returns whether the pointer should be freed or not. | 102 // Returns whether the pointer should be freed or not. |
| 103 bool derefBase() | 103 bool derefBase() |
| 104 { | 104 { |
| 105 ASSERT_WITH_SECURITY_IMPLICATION(!m_deletionHasBegun); | 105 ASSERT_WITH_SECURITY_IMPLICATION(!m_deletionHasBegun); |
| 106 #if CHECK_REF_COUNTED_LIFECYCLE | 106 #if CHECK_REF_COUNTED_LIFECYCLE |
| 107 ASSERT(m_verifier.isSafeToUse()); | 107 ASSERT(m_verifier.isSafeToUse()); |
| 108 ASSERT(!m_adoptionIsRequired); | 108 ASSERT(!m_adoptionIsRequired); |
| 109 #endif | 109 #endif |
| 110 | 110 |
| 111 ASSERT(m_refCount > 0); | 111 ASSERT(m_refCount > 0); |
| 112 --m_refCount; | 112 --m_refCount; |
| 113 if (!m_refCount) { | 113 if (!m_refCount) { |
| 114 #if SECURITY_ASSERT_ENABLED | 114 #if ENABLE(SECURITY_ASSERT) |
| 115 m_deletionHasBegun = true; | 115 m_deletionHasBegun = true; |
| 116 #endif | 116 #endif |
| 117 return true; | 117 return true; |
| 118 } | 118 } |
| 119 | 119 |
| 120 #if CHECK_REF_COUNTED_LIFECYCLE | 120 #if CHECK_REF_COUNTED_LIFECYCLE |
| 121 // Stop thread verification when the ref goes to 1 because it | 121 // Stop thread verification when the ref goes to 1 because it |
| 122 // is safe to be passed to another thread at this point. | 122 // is safe to be passed to another thread at this point. |
| 123 if (m_refCount == 1) | 123 if (m_refCount == 1) |
| 124 m_verifier.setShared(false); | 124 m_verifier.setShared(false); |
| 125 #endif | 125 #endif |
| 126 return false; | 126 return false; |
| 127 } | 127 } |
| 128 | 128 |
| 129 #if CHECK_REF_COUNTED_LIFECYCLE | 129 #if CHECK_REF_COUNTED_LIFECYCLE |
| 130 bool deletionHasBegun() const | 130 bool deletionHasBegun() const |
| 131 { | 131 { |
| 132 return m_deletionHasBegun; | 132 return m_deletionHasBegun; |
| 133 } | 133 } |
| 134 #endif | 134 #endif |
| 135 | 135 |
| 136 private: | 136 private: |
| 137 | 137 |
| 138 #if CHECK_REF_COUNTED_LIFECYCLE || SECURITY_ASSERT_ENABLED | 138 #if CHECK_REF_COUNTED_LIFECYCLE || ENABLE(SECURITY_ASSERT) |
| 139 friend void adopted(RefCountedBase*); | 139 friend void adopted(RefCountedBase*); |
| 140 #endif | 140 #endif |
| 141 | 141 |
| 142 int m_refCount; | 142 int m_refCount; |
| 143 #if SECURITY_ASSERT_ENABLED | 143 #if ENABLE(SECURITY_ASSERT) |
| 144 bool m_deletionHasBegun; | 144 bool m_deletionHasBegun; |
| 145 #endif | 145 #endif |
| 146 #if CHECK_REF_COUNTED_LIFECYCLE | 146 #if CHECK_REF_COUNTED_LIFECYCLE |
| 147 bool m_adoptionIsRequired; | 147 bool m_adoptionIsRequired; |
| 148 ThreadRestrictionVerifier m_verifier; | 148 ThreadRestrictionVerifier m_verifier; |
| 149 #endif | 149 #endif |
| 150 }; | 150 }; |
| 151 | 151 |
| 152 #if CHECK_REF_COUNTED_LIFECYCLE || SECURITY_ASSERT_ENABLED | 152 #if CHECK_REF_COUNTED_LIFECYCLE || ENABLE(SECURITY_ASSERT) |
| 153 inline void adopted(RefCountedBase* object) | 153 inline void adopted(RefCountedBase* object) |
| 154 { | 154 { |
| 155 if (!object) | 155 if (!object) |
| 156 return; | 156 return; |
| 157 ASSERT_WITH_SECURITY_IMPLICATION(!object->m_deletionHasBegun); | 157 ASSERT_WITH_SECURITY_IMPLICATION(!object->m_deletionHasBegun); |
| 158 #if CHECK_REF_COUNTED_LIFECYCLE | 158 #if CHECK_REF_COUNTED_LIFECYCLE |
| 159 object->m_adoptionIsRequired = false; | 159 object->m_adoptionIsRequired = false; |
| 160 #endif | 160 #endif |
| 161 } | 161 } |
| 162 #endif | 162 #endif |
| (...skipping 25 matching lines...) Expand all Loading... |
| 188 { | 188 { |
| 189 } | 189 } |
| 190 #endif | 190 #endif |
| 191 }; | 191 }; |
| 192 | 192 |
| 193 } // namespace WTF | 193 } // namespace WTF |
| 194 | 194 |
| 195 using WTF::RefCounted; | 195 using WTF::RefCounted; |
| 196 | 196 |
| 197 #endif // RefCounted_h | 197 #endif // RefCounted_h |
| OLD | NEW |