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 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 { | 234 { |
235 return ptr; | 235 return ptr; |
236 } | 236 } |
237 }; | 237 }; |
238 | 238 |
239 // |T| is |C*| or |const WeakPtr<C>&|. | 239 // |T| is |C*| or |const WeakPtr<C>&|. |
240 template <typename T> | 240 template <typename T> |
241 struct AllowCrossThreadAccessWrapper { | 241 struct AllowCrossThreadAccessWrapper { |
242 STACK_ALLOCATED(); | 242 STACK_ALLOCATED(); |
243 public: | 243 public: |
244 explicit AllowCrossThreadAccessWrapper(T value) : m_value(value) { } | |
245 T value() const { return m_value; } | 244 T value() const { return m_value; } |
246 private: | 245 private: |
| 246 // Only constructible from AllowCrossThreadAccess(). |
| 247 explicit AllowCrossThreadAccessWrapper(T value) : m_value(value) { } |
| 248 template <typename U> |
| 249 friend AllowCrossThreadAccessWrapper<U*> AllowCrossThreadAccess(U*); |
| 250 template <typename U> |
| 251 friend AllowCrossThreadAccessWrapper<const WeakPtr<U>&> AllowCrossThreadAcce
ss(const WeakPtr<U>&); |
| 252 |
247 // This raw pointer is safe since AllowCrossThreadAccessWrapper is | 253 // This raw pointer is safe since AllowCrossThreadAccessWrapper is |
248 // always stack-allocated. Ideally this should be Member<T> if T is | 254 // always stack-allocated. Ideally this should be Member<T> if T is |
249 // garbage-collected and T* otherwise, but we don't want to introduce | 255 // garbage-collected and T* otherwise, but we don't want to introduce |
250 // another template magic just for distinguishing Member<T> from T*. | 256 // another template magic just for distinguishing Member<T> from T*. |
251 // From the perspective of GC, T* always works correctly. | 257 // From the perspective of GC, T* always works correctly. |
252 GC_PLUGIN_IGNORE("") | 258 GC_PLUGIN_IGNORE("") |
253 T m_value; | 259 T m_value; |
254 }; | 260 }; |
255 | 261 |
256 template <typename T> | 262 template <typename T> |
(...skipping 11 matching lines...) Expand all Loading... |
268 | 274 |
269 template <typename T> | 275 template <typename T> |
270 AllowCrossThreadAccessWrapper<const WeakPtr<T>&> AllowCrossThreadAccess(const We
akPtr<T>& value) | 276 AllowCrossThreadAccessWrapper<const WeakPtr<T>&> AllowCrossThreadAccess(const We
akPtr<T>& value) |
271 { | 277 { |
272 return AllowCrossThreadAccessWrapper<const WeakPtr<T>&>(value); | 278 return AllowCrossThreadAccessWrapper<const WeakPtr<T>&>(value); |
273 } | 279 } |
274 | 280 |
275 } // namespace blink | 281 } // namespace blink |
276 | 282 |
277 #endif // CrossThreadCopier_h | 283 #endif // CrossThreadCopier_h |
OLD | NEW |