| 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 |
| 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 WTF_PassRefPtr_h | 21 #ifndef WTF_PassRefPtr_h |
| 22 #define WTF_PassRefPtr_h | 22 #define WTF_PassRefPtr_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/CrossThreadCopier.h" |
| 27 #include "wtf/ThreadSafeRefCounted.h" |
| 26 #include "wtf/TypeTraits.h" | 28 #include "wtf/TypeTraits.h" |
| 27 | 29 |
| 30 class SkRefCnt; |
| 31 |
| 28 namespace WTF { | 32 namespace WTF { |
| 29 | 33 |
| 30 template <typename T> class RefPtr; | 34 template <typename T> class RefPtr; |
| 31 template <typename T> class PassRefPtr; | 35 template <typename T> class PassRefPtr; |
| 32 template <typename T> PassRefPtr<T> adoptRef(T*); | 36 template <typename T> PassRefPtr<T> adoptRef(T*); |
| 33 | 37 |
| 34 inline void adopted(const void*) {} | 38 inline void adopted(const void*) {} |
| 35 | 39 |
| 36 // requireAdoption() is not overloaded for WTF::RefCounted, which has a built-in | 40 // requireAdoption() is not overloaded for WTF::RefCounted, which has a built-in |
| 37 // assumption that adoption is required. requireAdoption() is for bootstrapping | 41 // assumption that adoption is required. requireAdoption() is for bootstrapping |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 PassRefPtr& operator=(const PassRefPtr&) | 97 PassRefPtr& operator=(const PassRefPtr&) |
| 94 { | 98 { |
| 95 static_assert(!sizeof(T*), "PassRefPtr should never be assigned to"); | 99 static_assert(!sizeof(T*), "PassRefPtr should never be assigned to"); |
| 96 return *this; | 100 return *this; |
| 97 } | 101 } |
| 98 | 102 |
| 99 mutable T* m_ptr; | 103 mutable T* m_ptr; |
| 100 }; | 104 }; |
| 101 | 105 |
| 102 template <typename T> | 106 template <typename T> |
| 107 struct CrossThreadCopier<PassRefPtr<T>> : public CrossThreadCopierPassThrough<Pa
ssRefPtr<T>> { |
| 108 STATIC_ONLY(CrossThreadCopier); |
| 109 static_assert(IsSubclassOfTemplate<T, ThreadSafeRefCounted>::value || std::i
s_base_of<SkRefCnt, T>::value, "PassRefPtr<T> can be passed across threads only
if T is ThreadSafeRefCounted or SkRefCnt."); |
| 110 }; |
| 111 |
| 112 template <typename T> |
| 103 PassRefPtr<T> wrapPassRefPtr(T* ptr) | 113 PassRefPtr<T> wrapPassRefPtr(T* ptr) |
| 104 { | 114 { |
| 105 return PassRefPtr<T>(ptr); | 115 return PassRefPtr<T>(ptr); |
| 106 } | 116 } |
| 107 | 117 |
| 108 template <typename T> | 118 template <typename T> |
| 109 template <typename U> inline PassRefPtr<T>::PassRefPtr(const RefPtr<U>& o, Ensur
ePtrConvertibleArgDefn(U, T)) | 119 template <typename U> inline PassRefPtr<T>::PassRefPtr(const RefPtr<U>& o, Ensur
ePtrConvertibleArgDefn(U, T)) |
| 110 : m_ptr(o.get()) | 120 : m_ptr(o.get()) |
| 111 { | 121 { |
| 112 T* ptr = m_ptr; | 122 T* ptr = m_ptr; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 return p.get(); | 222 return p.get(); |
| 213 } | 223 } |
| 214 | 224 |
| 215 } // namespace WTF | 225 } // namespace WTF |
| 216 | 226 |
| 217 using WTF::PassRefPtr; | 227 using WTF::PassRefPtr; |
| 218 using WTF::adoptRef; | 228 using WTF::adoptRef; |
| 219 using WTF::static_pointer_cast; | 229 using WTF::static_pointer_cast; |
| 220 | 230 |
| 221 #endif // WTF_PassRefPtr_h | 231 #endif // WTF_PassRefPtr_h |
| OLD | NEW |