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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 struct CrossThreadCopier<CrossThreadPersistent<T>> : public CrossThreadCopierPas
sThrough<CrossThreadPersistent<T>> { | 148 struct CrossThreadCopier<CrossThreadPersistent<T>> : public CrossThreadCopierPas
sThrough<CrossThreadPersistent<T>> { |
149 STATIC_ONLY(CrossThreadCopier); | 149 STATIC_ONLY(CrossThreadCopier); |
150 }; | 150 }; |
151 | 151 |
152 template<typename T> | 152 template<typename T> |
153 struct CrossThreadCopier<CrossThreadWeakPersistent<T>> : public CrossThreadCopie
rPassThrough<CrossThreadWeakPersistent<T>> { | 153 struct CrossThreadCopier<CrossThreadWeakPersistent<T>> : public CrossThreadCopie
rPassThrough<CrossThreadWeakPersistent<T>> { |
154 STATIC_ONLY(CrossThreadCopier); | 154 STATIC_ONLY(CrossThreadCopier); |
155 }; | 155 }; |
156 | 156 |
157 template<typename T> | 157 template<typename T> |
| 158 struct CrossThreadCopier<WTF::UnretainedWrapper<T, WTF::CrossThreadAffinity>> :
public CrossThreadCopierPassThrough<WTF::UnretainedWrapper<T, WTF::CrossThreadAf
finity>> { |
| 159 STATIC_ONLY(CrossThreadCopier); |
| 160 }; |
| 161 |
| 162 template<typename T> |
158 struct CrossThreadCopier<WeakPtr<T>> : public CrossThreadCopierPassThrough<WeakP
tr<T>> { | 163 struct CrossThreadCopier<WeakPtr<T>> : public CrossThreadCopierPassThrough<WeakP
tr<T>> { |
159 STATIC_ONLY(CrossThreadCopier); | 164 STATIC_ONLY(CrossThreadCopier); |
160 }; | 165 }; |
161 | 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 }; |
(...skipping 42 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 a pointer type. | |
221 template <typename T> | |
222 struct AllowCrossThreadAccessWrapper { | |
223 STACK_ALLOCATED(); | |
224 public: | |
225 T value() const { return m_value; } | |
226 private: | |
227 // Only constructible from AllowCrossThreadAccess*(). | |
228 explicit AllowCrossThreadAccessWrapper(T value) : m_value(value) { } | |
229 template <typename U> | |
230 friend AllowCrossThreadAccessWrapper<U*> AllowCrossThreadAccess(U*); | |
231 | |
232 // This raw pointer is safe since AllowCrossThreadAccessWrapper is | |
233 // always stack-allocated. Ideally this should be Member<T> if T is | |
234 // garbage-collected and T* otherwise, but we don't want to introduce | |
235 // another template magic just for distinguishing Member<T> from T*. | |
236 // From the perspective of GC, T* always works correctly. | |
237 GC_PLUGIN_IGNORE("") | |
238 T m_value; | |
239 }; | |
240 | |
241 template <typename T> | |
242 struct CrossThreadCopier<AllowCrossThreadAccessWrapper<T>> { | |
243 STATIC_ONLY(CrossThreadCopier); | |
244 typedef T Type; | |
245 static Type copy(const AllowCrossThreadAccessWrapper<T>& wrapper) { return w
rapper.value(); } | |
246 }; | |
247 | |
248 template <typename T> | |
249 AllowCrossThreadAccessWrapper<T*> AllowCrossThreadAccess(T* value) | |
250 { | |
251 static_assert(!IsGarbageCollectedType<T>::value, "Use wrapCrossThreadPersist
ent() instead for garbage-collected pointers"); | |
252 static_assert(!WTF::IsSubclassOfTemplate<T, ThreadSafeRefCounted>::value, "U
se PassRefPtr<T> instead for ThreadSafeRefCounted"); | |
253 return AllowCrossThreadAccessWrapper<T*>(value); | |
254 } | |
255 | |
256 } // namespace blink | 225 } // namespace blink |
257 | 226 |
258 #endif // CrossThreadCopier_h | 227 #endif // CrossThreadCopier_h |
OLD | NEW |