OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reser
ved. | 2 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reser
ved. |
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 15 matching lines...) Expand all Loading... |
26 #include "wtf/TypeTraits.h" | 26 #include "wtf/TypeTraits.h" |
27 | 27 |
28 namespace WTF { | 28 namespace WTF { |
29 | 29 |
30 template<typename T> class RefPtr; | 30 template<typename T> class RefPtr; |
31 template<typename T> class PassRefPtr; | 31 template<typename T> class PassRefPtr; |
32 template<typename T> PassRefPtr<T> adoptRef(T*); | 32 template<typename T> PassRefPtr<T> adoptRef(T*); |
33 | 33 |
34 inline void adopted(const void*) { } | 34 inline void adopted(const void*) { } |
35 | 35 |
| 36 // requireAdoption() is not overloaded for WTF::RefCounted, which has a |
| 37 // built-in assumption that adoption is required. requireAdoption() is |
| 38 // for bootstrapping alternate reference count classes that are compatible |
| 39 // with ReftPtr/PassRefPtr but cannot have adoption checks enabled |
| 40 // by default, such as skia's SkRefCnt. The purpose of requireAdoption() |
| 41 // is to enable adoption checks only once it is known that the object will |
| 42 // be used with RefPtr/PassRefPtr. |
| 43 inline void requireAdoption(const void*) { } |
| 44 |
36 template<typename T> ALWAYS_INLINE void refIfNotNull(T* ptr) | 45 template<typename T> ALWAYS_INLINE void refIfNotNull(T* ptr) |
37 { | 46 { |
38 if (LIKELY(ptr != 0)) | 47 if (LIKELY(ptr != 0)) { |
| 48 requireAdoption(ptr); |
39 ptr->ref(); | 49 ptr->ref(); |
| 50 } |
40 } | 51 } |
41 | 52 |
42 template<typename T> ALWAYS_INLINE void derefIfNotNull(T* ptr) | 53 template<typename T> ALWAYS_INLINE void derefIfNotNull(T* ptr) |
43 { | 54 { |
44 if (LIKELY(ptr != 0)) | 55 if (LIKELY(ptr != 0)) |
45 ptr->deref(); | 56 ptr->deref(); |
46 } | 57 } |
47 | 58 |
48 template<typename T> class PassRefPtr { | 59 template<typename T> class PassRefPtr { |
49 public: | 60 public: |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 } | 180 } |
170 | 181 |
171 } // namespace WTF | 182 } // namespace WTF |
172 | 183 |
173 using WTF::PassRefPtr; | 184 using WTF::PassRefPtr; |
174 using WTF::adoptRef; | 185 using WTF::adoptRef; |
175 using WTF::static_pointer_cast; | 186 using WTF::static_pointer_cast; |
176 using WTF::const_pointer_cast; | 187 using WTF::const_pointer_cast; |
177 | 188 |
178 #endif // WTF_PassRefPtr_h | 189 #endif // WTF_PassRefPtr_h |
OLD | NEW |