OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009, 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2009, 2010 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 { | 152 { |
153 return pointer; // This is in fact a move. | 153 return pointer; // This is in fact a move. |
154 } | 154 } |
155 }; | 155 }; |
156 | 156 |
157 template<typename T> | 157 template<typename T> |
158 struct CrossThreadCopier<CrossThreadPersistent<T>> : public CrossThreadCopierPas
sThrough<CrossThreadPersistent<T>> { | 158 struct CrossThreadCopier<CrossThreadPersistent<T>> : public CrossThreadCopierPas
sThrough<CrossThreadPersistent<T>> { |
159 STATIC_ONLY(CrossThreadCopier); | 159 STATIC_ONLY(CrossThreadCopier); |
160 }; | 160 }; |
161 | 161 |
| 162 template<typename T> |
| 163 struct CrossThreadCopier<WeakPtr<T>> : public CrossThreadCopierPassThrough<WeakP
tr<T>> { |
| 164 STATIC_ONLY(CrossThreadCopier); |
| 165 }; |
| 166 |
162 template <typename T> | 167 template <typename T> |
163 struct CrossThreadCopier<WTF::PassedWrapper<T>> { | 168 struct CrossThreadCopier<WTF::PassedWrapper<T>> { |
164 STATIC_ONLY(CrossThreadCopier); | 169 STATIC_ONLY(CrossThreadCopier); |
165 using Type = WTF::PassedWrapper<typename CrossThreadCopier<T>::Type>; | 170 using Type = WTF::PassedWrapper<typename CrossThreadCopier<T>::Type>; |
166 static Type copy(WTF::PassedWrapper<T>&& value) { return passed(CrossThreadC
opier<T>::copy(value.moveOut())); } | 171 static Type copy(WTF::PassedWrapper<T>&& value) { return passed(CrossThreadC
opier<T>::copy(value.moveOut())); } |
167 }; | 172 }; |
168 | 173 |
169 template<typename T> | 174 template<typename T> |
170 struct CrossThreadCopier<CrossThreadWeakPersistentThisPointer<T>> : public Cross
ThreadCopierPassThrough<CrossThreadWeakPersistentThisPointer<T>> { | 175 struct CrossThreadCopier<CrossThreadWeakPersistentThisPointer<T>> : public Cross
ThreadCopierPassThrough<CrossThreadWeakPersistentThisPointer<T>> { |
171 STATIC_ONLY(CrossThreadCopier); | 176 STATIC_ONLY(CrossThreadCopier); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 struct CrossThreadCopier<Member<T>> { | 215 struct CrossThreadCopier<Member<T>> { |
211 STATIC_ONLY(CrossThreadCopier); | 216 STATIC_ONLY(CrossThreadCopier); |
212 static_assert(IsGarbageCollectedType<T>::value, "T must be a garbage-collect
ed type."); | 217 static_assert(IsGarbageCollectedType<T>::value, "T must be a garbage-collect
ed type."); |
213 typedef T* Type; | 218 typedef T* Type; |
214 static Type copy(const Member<T>& ptr) | 219 static Type copy(const Member<T>& ptr) |
215 { | 220 { |
216 return ptr; | 221 return ptr; |
217 } | 222 } |
218 }; | 223 }; |
219 | 224 |
220 // |T| is |C*| or |const WeakPtr<C>&|. | 225 // |T| is a pointer type. |
221 template <typename T> | 226 template <typename T> |
222 struct AllowCrossThreadAccessWrapper { | 227 struct AllowCrossThreadAccessWrapper { |
223 STACK_ALLOCATED(); | 228 STACK_ALLOCATED(); |
224 public: | 229 public: |
225 T value() const { return m_value; } | 230 T value() const { return m_value; } |
226 private: | 231 private: |
227 // Only constructible from AllowCrossThreadAccess(). | 232 // Only constructible from AllowCrossThreadAccess*(). |
228 explicit AllowCrossThreadAccessWrapper(T value) : m_value(value) { } | 233 explicit AllowCrossThreadAccessWrapper(T value) : m_value(value) { } |
229 template <typename U> | 234 template <typename U> |
230 friend AllowCrossThreadAccessWrapper<U*> AllowCrossThreadAccess(U*); | 235 friend AllowCrossThreadAccessWrapper<U*> AllowCrossThreadAccess(U*); |
231 template <typename U> | |
232 friend AllowCrossThreadAccessWrapper<const WeakPtr<U>&> AllowCrossThreadAcce
ss(const WeakPtr<U>&); | |
233 | 236 |
234 // This raw pointer is safe since AllowCrossThreadAccessWrapper is | 237 // This raw pointer is safe since AllowCrossThreadAccessWrapper is |
235 // always stack-allocated. Ideally this should be Member<T> if T is | 238 // always stack-allocated. Ideally this should be Member<T> if T is |
236 // garbage-collected and T* otherwise, but we don't want to introduce | 239 // garbage-collected and T* otherwise, but we don't want to introduce |
237 // another template magic just for distinguishing Member<T> from T*. | 240 // another template magic just for distinguishing Member<T> from T*. |
238 // From the perspective of GC, T* always works correctly. | 241 // From the perspective of GC, T* always works correctly. |
239 GC_PLUGIN_IGNORE("") | 242 GC_PLUGIN_IGNORE("") |
240 T m_value; | 243 T m_value; |
241 }; | 244 }; |
242 | 245 |
243 template <typename T> | 246 template <typename T> |
244 struct CrossThreadCopier<AllowCrossThreadAccessWrapper<T>> { | 247 struct CrossThreadCopier<AllowCrossThreadAccessWrapper<T>> { |
245 STATIC_ONLY(CrossThreadCopier); | 248 STATIC_ONLY(CrossThreadCopier); |
246 typedef T Type; | 249 typedef T Type; |
247 static Type copy(const AllowCrossThreadAccessWrapper<T>& wrapper) { return w
rapper.value(); } | 250 static Type copy(const AllowCrossThreadAccessWrapper<T>& wrapper) { return w
rapper.value(); } |
248 }; | 251 }; |
249 | 252 |
250 template <typename T> | 253 template <typename T> |
251 AllowCrossThreadAccessWrapper<T*> AllowCrossThreadAccess(T* value) | 254 AllowCrossThreadAccessWrapper<T*> AllowCrossThreadAccess(T* value) |
252 { | 255 { |
253 static_assert(!blink::IsGarbageCollectedType<T>::value, "Use wrapCrossThread
Persistent() instead for garbage-collected pointers"); | 256 static_assert(!blink::IsGarbageCollectedType<T>::value, "Use wrapCrossThread
Persistent() instead for garbage-collected pointers"); |
254 static_assert(!WTF::IsSubclassOfTemplate<T, ThreadSafeRefCounted>::value, "U
se PassRefPtr<T> instead for ThreadSafeRefCounted"); | 257 static_assert(!WTF::IsSubclassOfTemplate<T, ThreadSafeRefCounted>::value, "U
se PassRefPtr<T> instead for ThreadSafeRefCounted"); |
255 return AllowCrossThreadAccessWrapper<T*>(value); | 258 return AllowCrossThreadAccessWrapper<T*>(value); |
256 } | 259 } |
257 | 260 |
258 template <typename T> | |
259 AllowCrossThreadAccessWrapper<const WeakPtr<T>&> AllowCrossThreadAccess(const We
akPtr<T>& value) | |
260 { | |
261 return AllowCrossThreadAccessWrapper<const WeakPtr<T>&>(value); | |
262 } | |
263 | |
264 } // namespace blink | 261 } // namespace blink |
265 | 262 |
266 #endif // CrossThreadCopier_h | 263 #endif // CrossThreadCopier_h |
OLD | NEW |