| 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 "platform/wtf/Allocator.h" | 24 #include "platform/wtf/Allocator.h" |
| 25 #include "platform/wtf/Assertions.h" | 25 #include "platform/wtf/Assertions.h" |
| 26 #include "platform/wtf/Noncopyable.h" | 26 #include "platform/wtf/Noncopyable.h" |
| 27 #include "platform/wtf/WTFExport.h" | 27 #include "platform/wtf/WTFExport.h" |
| 28 | 28 |
| 29 #if ENABLE(INSTANCE_COUNTER) | |
| 30 #include "platform/wtf/InstanceCounter.h" | |
| 31 #endif | |
| 32 | |
| 33 #if DCHECK_IS_ON() | 29 #if DCHECK_IS_ON() |
| 34 #define CHECK_REF_COUNTED_LIFECYCLE 1 | 30 #define CHECK_REF_COUNTED_LIFECYCLE 1 |
| 35 #include "platform/wtf/ThreadRestrictionVerifier.h" | 31 #include "platform/wtf/ThreadRestrictionVerifier.h" |
| 36 #else | 32 #else |
| 37 #define CHECK_REF_COUNTED_LIFECYCLE 0 | 33 #define CHECK_REF_COUNTED_LIFECYCLE 0 |
| 38 #endif | 34 #endif |
| 39 | 35 |
| 40 namespace WTF { | 36 namespace WTF { |
| 41 | 37 |
| 42 // This base class holds the non-template methods and attributes. | 38 // This base class holds the non-template methods and attributes. |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 // new. | 144 // new. |
| 149 USING_FAST_MALLOC(T); | 145 USING_FAST_MALLOC(T); |
| 150 | 146 |
| 151 public: | 147 public: |
| 152 void Deref() const { | 148 void Deref() const { |
| 153 if (DerefBase()) | 149 if (DerefBase()) |
| 154 delete static_cast<const T*>(this); | 150 delete static_cast<const T*>(this); |
| 155 } | 151 } |
| 156 | 152 |
| 157 protected: | 153 protected: |
| 158 #if ENABLE(INSTANCE_COUNTER) | |
| 159 RefCounted() { incrementInstanceCount<T>(static_cast<T*>(this)); } | |
| 160 | |
| 161 ~RefCounted() { decrementInstanceCount<T>(static_cast<T*>(this)); } | |
| 162 #else | |
| 163 RefCounted() {} | 154 RefCounted() {} |
| 164 #endif | |
| 165 }; | 155 }; |
| 166 | 156 |
| 167 // Allows subclasses to use the default copy constructor. | 157 // Allows subclasses to use the default copy constructor. |
| 168 template <typename T> | 158 template <typename T> |
| 169 class RefCountedCopyable : public RefCounted<T> { | 159 class RefCountedCopyable : public RefCounted<T> { |
| 170 protected: | 160 protected: |
| 171 RefCountedCopyable() = default; | 161 RefCountedCopyable() = default; |
| 172 RefCountedCopyable(const RefCountedCopyable&) : RefCounted<T>() {} | 162 RefCountedCopyable(const RefCountedCopyable&) : RefCounted<T>() {} |
| 173 }; | 163 }; |
| 174 | 164 |
| 175 } // namespace WTF | 165 } // namespace WTF |
| 176 | 166 |
| 177 using WTF::RefCounted; | 167 using WTF::RefCounted; |
| 178 using WTF::RefCountedCopyable; | 168 using WTF::RefCountedCopyable; |
| 179 | 169 |
| 180 #endif // RefCounted_h | 170 #endif // RefCounted_h |
| OLD | NEW |