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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 template <typename T> | 56 template <typename T> |
57 struct CrossThreadCopierPassThrough { | 57 struct CrossThreadCopierPassThrough { |
58 STATIC_ONLY(CrossThreadCopierPassThrough); | 58 STATIC_ONLY(CrossThreadCopierPassThrough); |
59 typedef T Type; | 59 typedef T Type; |
60 static Type copy(const T& parameter) | 60 static Type copy(const T& parameter) |
61 { | 61 { |
62 return parameter; | 62 return parameter; |
63 } | 63 } |
64 }; | 64 }; |
65 | 65 |
66 template <bool isConvertibleToInteger, bool isThreadSafeRefCounted, bool isGarba
geCollected, typename T> | 66 template <typename T, bool isArithmeticOrEnum, bool isThreadSafeRefCounted, bool
isGarbageCollected> |
67 struct CrossThreadCopierBase; | 67 struct CrossThreadCopierBase; |
68 | 68 |
69 // Integers get passed through without any changes. | 69 // Arithmetic values (integers or floats) and enums can be safely copied. |
70 template <typename T> | 70 template <typename T, bool isThreadSafeRefCounted, bool isGarbageCollected> |
71 struct CrossThreadCopierBase<true, false, false, T> : public CrossThreadCopierPa
ssThrough<T> { | 71 struct CrossThreadCopierBase<T, true, isThreadSafeRefCounted, isGarbageCollected
> : public CrossThreadCopierPassThrough<T> { |
72 STATIC_ONLY(CrossThreadCopierBase); | 72 STATIC_ONLY(CrossThreadCopierBase); |
73 }; | 73 }; |
74 | 74 |
75 // Custom copy methods. | 75 // Custom copy method for ThreadSafeRefCounted. |
76 template <typename T> | 76 template <typename T, bool isGarbageCollected> |
77 struct CrossThreadCopierBase<false, true, false, T> { | 77 struct CrossThreadCopierBase<T, false, true, isGarbageCollected> { |
78 STATIC_ONLY(CrossThreadCopierBase); | 78 STATIC_ONLY(CrossThreadCopierBase); |
79 typedef typename WTF::RemoveTemplate<T, RefPtr>::Type TypeWithoutRefPtr; | 79 typedef typename WTF::RemoveTemplate<T, RefPtr>::Type TypeWithoutRefPtr; |
80 typedef typename WTF::RemoveTemplate<TypeWithoutRefPtr, PassRefPtr>::Type Ty
peWithoutPassRefPtr; | 80 typedef typename WTF::RemoveTemplate<TypeWithoutRefPtr, PassRefPtr>::Type Ty
peWithoutPassRefPtr; |
81 typedef typename std::remove_pointer<TypeWithoutPassRefPtr>::type RefCounted
Type; | 81 typedef typename std::remove_pointer<TypeWithoutPassRefPtr>::type RefCounted
Type; |
82 | 82 |
83 // Verify that only one of the above did a change. | 83 // Verify that only one of the above did a change. |
84 static_assert((std::is_same<RefPtr<RefCountedType>, T>::value | 84 static_assert((std::is_same<RefPtr<RefCountedType>, T>::value |
85 || std::is_same<PassRefPtr<RefCountedType>, T>::value | 85 || std::is_same<PassRefPtr<RefCountedType>, T>::value |
86 || std::is_same<RefCountedType*, T>::value), | 86 || std::is_same<RefCountedType*, T>::value), |
87 "only one type modification should be allowed"); | 87 "only one type modification should be allowed"); |
88 | 88 |
89 typedef PassRefPtr<RefCountedType> Type; | 89 typedef PassRefPtr<RefCountedType> Type; |
90 static Type copy(const T& refPtr) | 90 static Type copy(const T& refPtr) |
91 { | 91 { |
92 return refPtr; | 92 return refPtr; |
93 } | 93 } |
94 }; | 94 }; |
95 | 95 |
| 96 // A pointer to GarbageCollected. |
96 template <typename T> | 97 template <typename T> |
97 struct CrossThreadCopierBase<false, false, true, T> { | 98 struct CrossThreadCopierBase<T, false, false, true> { |
98 STATIC_ONLY(CrossThreadCopierBase); | 99 STATIC_ONLY(CrossThreadCopierBase); |
99 typedef typename std::remove_pointer<T>::type TypeWithoutPointer; | 100 typedef typename std::remove_pointer<T>::type TypeWithoutPointer; |
100 typedef RawPtr<TypeWithoutPointer> Type; | 101 typedef RawPtr<TypeWithoutPointer> Type; |
101 static Type copy(const T& ptr) | 102 static Type copy(const T& ptr) |
102 { | 103 { |
103 return ptr; | 104 return ptr; |
104 } | 105 } |
105 }; | 106 }; |
106 | 107 |
107 template <typename T> | 108 template <typename T> |
108 struct CrossThreadCopier : public CrossThreadCopierBase<std::is_convertible<T, i
nt>::value, | 109 struct CrossThreadCopier : public CrossThreadCopierBase< |
| 110 T, |
| 111 std::is_arithmetic<T>::value || std::is_enum<T>::value, |
109 WTF::IsSubclassOfTemplate<typename WTF::RemoveTemplate<T, RefPtr>::Type, Thr
eadSafeRefCounted>::value | 112 WTF::IsSubclassOfTemplate<typename WTF::RemoveTemplate<T, RefPtr>::Type, Thr
eadSafeRefCounted>::value |
110 || WTF::IsSubclassOfTemplate<typename std::remove_pointer<T>::type, ThreadSa
feRefCounted>::value | 113 || WTF::IsSubclassOfTemplate<typename std::remove_pointer<T>::type, ThreadSa
feRefCounted>::value |
111 || WTF::IsSubclassOfTemplate<typename WTF::RemoveTemplate<T, PassRefPtr>::Ty
pe, ThreadSafeRefCounted>::value, | 114 || WTF::IsSubclassOfTemplate<typename WTF::RemoveTemplate<T, PassRefPtr>::Ty
pe, ThreadSafeRefCounted>::value, |
112 WTF::IsSubclassOfTemplate<typename std::remove_pointer<T>::type, GarbageColl
ected>::value, | 115 WTF::IsSubclassOfTemplate<typename std::remove_pointer<T>::type, GarbageColl
ected>::value> { |
113 T> { | |
114 STATIC_ONLY(CrossThreadCopier); | 116 STATIC_ONLY(CrossThreadCopier); |
115 }; | 117 }; |
116 | 118 |
117 // CrossThreadCopier specializations follow. | 119 // CrossThreadCopier specializations follow. |
118 | 120 |
119 // nullptr_t can be passed through without any changes. | 121 // nullptr_t can be passed through without any changes. |
120 template <> | 122 template <> |
121 struct CrossThreadCopier<std::nullptr_t> : public CrossThreadCopierPassThrough<s
td::nullptr_t> { | 123 struct CrossThreadCopier<std::nullptr_t> : public CrossThreadCopierPassThrough<s
td::nullptr_t> { |
122 STATIC_ONLY(CrossThreadCopier); | 124 STATIC_ONLY(CrossThreadCopier); |
123 }; | 125 }; |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 | 256 |
255 template <typename T> | 257 template <typename T> |
256 AllowCrossThreadAccessWrapper<const WeakPtr<T>&> AllowCrossThreadAccess(const We
akPtr<T>& value) | 258 AllowCrossThreadAccessWrapper<const WeakPtr<T>&> AllowCrossThreadAccess(const We
akPtr<T>& value) |
257 { | 259 { |
258 return AllowCrossThreadAccessWrapper<const WeakPtr<T>&>(value); | 260 return AllowCrossThreadAccessWrapper<const WeakPtr<T>&>(value); |
259 } | 261 } |
260 | 262 |
261 } // namespace blink | 263 } // namespace blink |
262 | 264 |
263 #endif // CrossThreadCopier_h | 265 #endif // CrossThreadCopier_h |
OLD | NEW |