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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 || WTF::IsSameType<RefCountedType*, T>::value), | 87 || WTF::IsSameType<RefCountedType*, T>::value), |
88 "only one type modification should be allowed"); | 88 "only one type modification should be allowed"); |
89 | 89 |
90 typedef PassRefPtr<RefCountedType> Type; | 90 typedef PassRefPtr<RefCountedType> Type; |
91 static Type copy(const T& refPtr) | 91 static Type copy(const T& refPtr) |
92 { | 92 { |
93 return refPtr; | 93 return refPtr; |
94 } | 94 } |
95 }; | 95 }; |
96 | 96 |
97 template<typename T> struct CrossThreadCopierBase<false, false, false, PassO
wnPtr<T> > { | 97 template<typename T> struct CrossThreadCopierBase<false, false, false, PassO
wnPtr<T>> { |
98 typedef PassOwnPtr<T> Type; | 98 typedef PassOwnPtr<T> Type; |
99 static Type copy(Type ownPtr) | 99 static Type copy(Type ownPtr) |
100 { | 100 { |
101 return ownPtr; | 101 return ownPtr; |
102 } | 102 } |
103 }; | 103 }; |
104 | 104 |
105 template<typename T> struct CrossThreadCopierBase<false, false, false, WeakM
ember<T>*> { | 105 template<typename T> struct CrossThreadCopierBase<false, false, false, WeakM
ember<T>*> { |
106 typedef WeakMember<T>* Type; | 106 typedef WeakMember<T>* Type; |
107 static Type copy(Type ptr) | 107 static Type copy(Type ptr) |
(...skipping 29 matching lines...) Expand all Loading... |
137 | 137 |
138 template<typename T> struct CrossThreadCopierBase<false, false, true, T> { | 138 template<typename T> struct CrossThreadCopierBase<false, false, true, T> { |
139 typedef typename WTF::RemovePointer<T>::Type TypeWithoutPointer; | 139 typedef typename WTF::RemovePointer<T>::Type TypeWithoutPointer; |
140 typedef RawPtr<TypeWithoutPointer> Type; | 140 typedef RawPtr<TypeWithoutPointer> Type; |
141 static Type copy(const T& ptr) | 141 static Type copy(const T& ptr) |
142 { | 142 { |
143 return ptr; | 143 return ptr; |
144 } | 144 } |
145 }; | 145 }; |
146 | 146 |
147 template<typename T> struct CrossThreadCopierBase<false, false, true, RawPtr
<T> > { | 147 template<typename T> struct CrossThreadCopierBase<false, false, true, RawPtr
<T>> { |
148 typedef RawPtr<T> Type; | 148 typedef RawPtr<T> Type; |
149 static Type copy(const Type& ptr) | 149 static Type copy(const Type& ptr) |
150 { | 150 { |
151 return ptr; | 151 return ptr; |
152 } | 152 } |
153 }; | 153 }; |
154 | 154 |
155 template<typename T> struct CrossThreadCopierBase<false, false, true, Member
<T> > { | 155 template<typename T> struct CrossThreadCopierBase<false, false, true, Member
<T>> { |
156 typedef RawPtr<T> Type; | 156 typedef RawPtr<T> Type; |
157 static Type copy(const Member<T>& ptr) | 157 static Type copy(const Member<T>& ptr) |
158 { | 158 { |
159 return ptr; | 159 return ptr; |
160 } | 160 } |
161 }; | 161 }; |
162 | 162 |
163 template<typename T> struct CrossThreadCopierBase<false, false, true, WeakMe
mber<T> > { | 163 template<typename T> struct CrossThreadCopierBase<false, false, true, WeakMe
mber<T>> { |
164 typedef RawPtr<T> Type; | 164 typedef RawPtr<T> Type; |
165 static Type copy(const WeakMember<T>& ptr) | 165 static Type copy(const WeakMember<T>& ptr) |
166 { | 166 { |
167 return ptr; | 167 return ptr; |
168 } | 168 } |
169 }; | 169 }; |
170 | 170 |
171 template<typename T> struct CrossThreadCopier : public CrossThreadCopierBase
<WTF::IsConvertibleToInteger<T>::value, | 171 template<typename T> struct CrossThreadCopier : public CrossThreadCopierBase
<WTF::IsConvertibleToInteger<T>::value, |
172 WTF::IsSubclassOfTemplate<typename WTF::RemoveTemplate<T, RefPtr>::Type,
ThreadSafeRefCounted>::value | 172 WTF::IsSubclassOfTemplate<typename WTF::RemoveTemplate<T, RefPtr>::Type,
ThreadSafeRefCounted>::value |
173 || WTF::IsSubclassOfTemplate<typename WTF::RemovePointer<T>::Type, T
hreadSafeRefCounted>::value | 173 || WTF::IsSubclassOfTemplate<typename WTF::RemovePointer<T>::Type, T
hreadSafeRefCounted>::value |
(...skipping 13 matching lines...) Expand all Loading... |
187 private: | 187 private: |
188 // This raw pointer is safe since AllowCrossThreadAccessWrapper is | 188 // This raw pointer is safe since AllowCrossThreadAccessWrapper is |
189 // always stack-allocated. Ideally this should be Member<T> if T is | 189 // always stack-allocated. Ideally this should be Member<T> if T is |
190 // garbage-collected and T* otherwise, but we don't want to introduce | 190 // garbage-collected and T* otherwise, but we don't want to introduce |
191 // another template magic just for distinguishing Member<T> from T*. | 191 // another template magic just for distinguishing Member<T> from T*. |
192 // From the perspective of GC, T* always works correctly. | 192 // From the perspective of GC, T* always works correctly. |
193 GC_PLUGIN_IGNORE("") | 193 GC_PLUGIN_IGNORE("") |
194 T* m_value; | 194 T* m_value; |
195 }; | 195 }; |
196 | 196 |
197 template<typename T> struct CrossThreadCopierBase<false, false, false, Allow
CrossThreadAccessWrapper<T> > { | 197 template<typename T> struct CrossThreadCopierBase<false, false, false, Allow
CrossThreadAccessWrapper<T>> { |
198 typedef T* Type; | 198 typedef T* Type; |
199 static Type copy(const AllowCrossThreadAccessWrapper<T>& wrapper) { retu
rn wrapper.value(); } | 199 static Type copy(const AllowCrossThreadAccessWrapper<T>& wrapper) { retu
rn wrapper.value(); } |
200 }; | 200 }; |
201 | 201 |
202 template<typename T> AllowCrossThreadAccessWrapper<T> AllowCrossThreadAccess
(T* value) | 202 template<typename T> AllowCrossThreadAccessWrapper<T> AllowCrossThreadAccess
(T* value) |
203 { | 203 { |
204 return AllowCrossThreadAccessWrapper<T>(value); | 204 return AllowCrossThreadAccessWrapper<T>(value); |
205 } | 205 } |
206 | 206 |
207 // FIXME: Move to a different header file. AllowAccessLater is for cross-thr
ead access | 207 // FIXME: Move to a different header file. AllowAccessLater is for cross-thr
ead access |
208 // that is not cross-thread (tasks posted to a queue guaranteed to run on th
e same thread). | 208 // that is not cross-thread (tasks posted to a queue guaranteed to run on th
e same thread). |
209 template<typename T> struct AllowAccessLaterWrapper { | 209 template<typename T> struct AllowAccessLaterWrapper { |
210 public: | 210 public: |
211 explicit AllowAccessLaterWrapper(T* value) : m_value(value) { } | 211 explicit AllowAccessLaterWrapper(T* value) : m_value(value) { } |
212 T* value() const { return m_value; } | 212 T* value() const { return m_value; } |
213 private: | 213 private: |
214 // This raw pointer is safe since AllowAccessLaterWrapper is | 214 // This raw pointer is safe since AllowAccessLaterWrapper is |
215 // always stack-allocated. Ideally this should be Member<T> if T is | 215 // always stack-allocated. Ideally this should be Member<T> if T is |
216 // garbage-collected and T* otherwise, but we don't want to introduce | 216 // garbage-collected and T* otherwise, but we don't want to introduce |
217 // another template magic just for distinguishing Member<T> from T*. | 217 // another template magic just for distinguishing Member<T> from T*. |
218 // From the perspective of GC, T* always works correctly. | 218 // From the perspective of GC, T* always works correctly. |
219 GC_PLUGIN_IGNORE("") | 219 GC_PLUGIN_IGNORE("") |
220 T* m_value; | 220 T* m_value; |
221 }; | 221 }; |
222 | 222 |
223 template<typename T> struct CrossThreadCopierBase<false, false, false, Allow
AccessLaterWrapper<T> > { | 223 template<typename T> struct CrossThreadCopierBase<false, false, false, Allow
AccessLaterWrapper<T>> { |
224 typedef T* Type; | 224 typedef T* Type; |
225 static Type copy(const AllowAccessLaterWrapper<T>& wrapper) { return wra
pper.value(); } | 225 static Type copy(const AllowAccessLaterWrapper<T>& wrapper) { return wra
pper.value(); } |
226 }; | 226 }; |
227 | 227 |
228 template<typename T> AllowAccessLaterWrapper<T> AllowAccessLater(T* value) | 228 template<typename T> AllowAccessLaterWrapper<T> AllowAccessLater(T* value) |
229 { | 229 { |
230 return AllowAccessLaterWrapper<T>(value); | 230 return AllowAccessLaterWrapper<T>(value); |
231 } | 231 } |
232 | 232 |
233 | 233 |
234 } // namespace blink | 234 } // namespace blink |
235 | 235 |
236 #endif // CrossThreadCopier_h | 236 #endif // CrossThreadCopier_h |
OLD | NEW |