OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
92 void release() | 92 void release() |
93 { | 93 { |
94 WTF::derefIfNotNull(m_ptr); | 94 WTF::derefIfNotNull(m_ptr); |
95 m_ptr = 0; | 95 m_ptr = 0; |
96 } | 96 } |
97 | 97 |
98 private: | 98 private: |
99 T* m_ptr; | 99 T* m_ptr; |
100 }; | 100 }; |
101 | 101 |
102 template <typename T> | |
103 struct WebPrivatePtrPersistentIsCrossThreadAccessible { | |
104 private: | |
105 using YesType = char; | |
106 struct NoType { | |
107 char padding[8]; | |
108 }; | |
109 | |
110 template <typename U> static YesType checkMarker(typename U::IsCrossThreadAc cessibleMarker*); | |
111 template <typename U> static NoType checkMarker(...); | |
112 public: | |
113 static const bool value = sizeof(checkMarker<T>(nullptr)) == sizeof(YesType) ; | |
114 }; | |
115 | |
116 template <typename T, bool = WebPrivatePtrPersistentIsCrossThreadAccessible<T>:: value> | |
117 struct WebPrivatePtrPersistentStorageType { | |
118 public: | |
119 using type = Persistent<T>; | |
120 }; | |
121 | |
122 template <typename T> | |
123 struct WebPrivatePtrPersistentStorageType<T, true> { | |
124 public: | |
125 using type = CrossThreadPersistent<T>; | |
haraken
2015/07/23 01:41:41
How about making CrossThreadPersistent by default?
| |
126 }; | |
127 | |
102 template<typename T> | 128 template<typename T> |
103 class PtrStorageImpl<T, GarbageCollectedLifetime> { | 129 class PtrStorageImpl<T, GarbageCollectedLifetime> { |
104 public: | 130 public: |
105 void assign(const RawPtr<T>& val) | 131 void assign(const RawPtr<T>& val) |
106 { | 132 { |
107 if (!val) { | 133 if (!val) { |
108 release(); | 134 release(); |
109 return; | 135 return; |
110 } | 136 } |
111 | 137 |
112 if (!m_handle) | 138 if (!m_handle) |
113 m_handle = new Persistent<T>(); | 139 m_handle = new (typename WebPrivatePtrPersistentStorageType<T>::type )(); |
114 | 140 |
115 (*m_handle) = val; | 141 (*m_handle) = val; |
116 } | 142 } |
117 | 143 |
118 void assign(T* ptr) { assign(RawPtr<T>(ptr)); } | 144 void assign(T* ptr) { assign(RawPtr<T>(ptr)); } |
119 template<typename U> void assign(const RawPtr<U>& val) { assign(RawPtr<T>(va l)); } | 145 template<typename U> void assign(const RawPtr<U>& val) { assign(RawPtr<T>(va l)); } |
120 | 146 |
121 void assign(const PtrStorageImpl& other) { assign(other.get()); } | 147 void assign(const PtrStorageImpl& other) { assign(other.get()); } |
122 | 148 |
123 void moveFrom(PtrStorageImpl& other) | 149 void moveFrom(PtrStorageImpl& other) |
124 { | 150 { |
125 release(); | 151 release(); |
126 m_handle = other.m_handle; | 152 m_handle = other.m_handle; |
127 other.m_handle = 0; | 153 other.m_handle = 0; |
128 } | 154 } |
129 | 155 |
130 T* get() const { return m_handle ? m_handle->get() : 0; } | 156 T* get() const { return m_handle ? m_handle->get() : 0; } |
131 | 157 |
132 void release() | 158 void release() |
133 { | 159 { |
134 delete m_handle; | 160 delete m_handle; |
135 m_handle = 0; | 161 m_handle = 0; |
136 } | 162 } |
137 | 163 |
138 private: | 164 private: |
139 Persistent<T>* m_handle; | 165 typename WebPrivatePtrPersistentStorageType<T>::type* m_handle; |
140 }; | 166 }; |
141 | 167 |
142 template<typename T> | 168 template<typename T> |
143 class PtrStorageImpl<T, RefCountedGarbageCollectedLifetime> : public PtrStorageI mpl<T, GarbageCollectedLifetime> { | 169 class PtrStorageImpl<T, RefCountedGarbageCollectedLifetime> : public PtrStorageI mpl<T, GarbageCollectedLifetime> { |
144 public: | 170 public: |
145 void assign(const PassRefPtrWillBeRawPtr<T>& val) { PtrStorageImpl<T, Garbag eCollectedLifetime>::assign(val.get()); } | 171 void assign(const PassRefPtrWillBeRawPtr<T>& val) { PtrStorageImpl<T, Garbag eCollectedLifetime>::assign(val.get()); } |
146 | 172 |
147 void assign(const PtrStorageImpl& other) { PtrStorageImpl<T, GarbageCollecte dLifetime>::assign(other.get()); } | 173 void assign(const PtrStorageImpl& other) { PtrStorageImpl<T, GarbageCollecte dLifetime>::assign(other.get()); } |
148 }; | 174 }; |
149 | 175 |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
281 // Disable the copy constructor; classes that contain a WebPrivatePtr | 307 // Disable the copy constructor; classes that contain a WebPrivatePtr |
282 // should implement their copy constructor using assign(). | 308 // should implement their copy constructor using assign(). |
283 WebPrivatePtr(const WebPrivatePtr<T>&); | 309 WebPrivatePtr(const WebPrivatePtr<T>&); |
284 | 310 |
285 void* m_storage; | 311 void* m_storage; |
286 }; | 312 }; |
287 | 313 |
288 } // namespace blink | 314 } // namespace blink |
289 | 315 |
290 #endif | 316 #endif |
OLD | NEW |