Index: public/platform/WebPrivatePtr.h |
diff --git a/public/platform/WebPrivatePtr.h b/public/platform/WebPrivatePtr.h |
index f62961f062b7e81375a0ff153d9aa1659edc8968..b7763cf9ce495a4ecbf0c0bde307bb783af3deda 100644 |
--- a/public/platform/WebPrivatePtr.h |
+++ b/public/platform/WebPrivatePtr.h |
@@ -99,6 +99,32 @@ private: |
T* m_ptr; |
}; |
+template <typename T> |
+struct WebPrivatePtrPersistentIsCrossThreadAccessible { |
+private: |
+ using YesType = char; |
+ struct NoType { |
+ char padding[8]; |
+ }; |
+ |
+ template <typename U> static YesType checkMarker(typename U::IsCrossThreadAccessibleMarker*); |
+ template <typename U> static NoType checkMarker(...); |
+public: |
+ static const bool value = sizeof(checkMarker<T>(nullptr)) == sizeof(YesType); |
+}; |
+ |
+template <typename T, bool = WebPrivatePtrPersistentIsCrossThreadAccessible<T>::value> |
+struct WebPrivatePtrPersistentStorageType { |
+public: |
+ using type = Persistent<T>; |
+}; |
+ |
+template <typename T> |
+struct WebPrivatePtrPersistentStorageType<T, true> { |
+public: |
+ using type = CrossThreadPersistent<T>; |
haraken
2015/07/23 01:41:41
How about making CrossThreadPersistent by default?
|
+}; |
+ |
template<typename T> |
class PtrStorageImpl<T, GarbageCollectedLifetime> { |
public: |
@@ -110,7 +136,7 @@ public: |
} |
if (!m_handle) |
- m_handle = new Persistent<T>(); |
+ m_handle = new (typename WebPrivatePtrPersistentStorageType<T>::type)(); |
(*m_handle) = val; |
} |
@@ -136,7 +162,7 @@ public: |
} |
private: |
- Persistent<T>* m_handle; |
+ typename WebPrivatePtrPersistentStorageType<T>::type* m_handle; |
}; |
template<typename T> |