- Revision
- 94986
- Author
- le...@chromium.org
- Date
- 2011-09-12 15:48:38 -0700 (Mon, 12 Sep 2011)
Log Message
Make the ThreadSafeRefCounted support in CrossThreadCopier work for T*.
https://bugs.webkit.org/show_bug.cgi?id=67947
Reviewed by Adam Barth.
The changes are tested by compiling and added compile asserts to do some verification as well.
* platform/CrossThreadCopier.cpp:
Added some compile asserts to verify various match and non-matches for CrossThreadCopier.
* platform/CrossThreadCopier.h:
Added a typedef to convert T* to T, just like the typedef's to remove RefPtr and PassRefPtr.
Added a compile assert to verify that only one of the typedefs did anything.
(CrossThreadCopierBase<false, true, T>::copy): Remove "get" as it is unnecessary.
It shouldn't have been here (PassRefPtr and RefPtr easily and sometimes more efficiently
convert to PassRefPtr without get). Also, a raw pointer doesn't have a get() method.
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (94985 => 94986)
--- trunk/Source/WebCore/ChangeLog 2011-09-12 22:43:51 UTC (rev 94985)
+++ trunk/Source/WebCore/ChangeLog 2011-09-12 22:48:38 UTC (rev 94986)
@@ -1,3 +1,21 @@
+2011-09-12 David Levin <le...@chromium.org>
+
+ Make the ThreadSafeRefCounted support in CrossThreadCopier work for T*.
+ https://bugs.webkit.org/show_bug.cgi?id=67947
+
+ Reviewed by Adam Barth.
+
+ The changes are tested by compiling and added compile asserts to do some verification as well.
+
+ * platform/CrossThreadCopier.cpp:
+ Added some compile asserts to verify various match and non-matches for CrossThreadCopier.
+ * platform/CrossThreadCopier.h:
+ Added a typedef to convert T* to T, just like the typedef's to remove RefPtr and PassRefPtr.
+ Added a compile assert to verify that only one of the typedef did anything.
+ (CrossThreadCopierBase<false, true, T>::copy): Remove "get" as it is unnecessary.
+ It shouldn't have been here (PassRefPtr and RefPtr easily and sometimes more efficiently
+ convert to PassRefPtr without get). Also, a raw pointer doesn't have a get() method.
+
2011-09-12 Chris Rogers <crog...@google.com>
Address lifetime issues in OfflineAudioDestinationNode
Modified: trunk/Source/WebCore/platform/CrossThreadCopier.cpp (94985 => 94986)
--- trunk/Source/WebCore/platform/CrossThreadCopier.cpp 2011-09-12 22:43:51 UTC (rev 94985)
+++ trunk/Source/WebCore/platform/CrossThreadCopier.cpp 2011-09-12 22:48:38 UTC (rev 94986)
@@ -39,6 +39,8 @@
#include "ResourceResponse.h"
#include "SerializedScriptValue.h"
+#include <wtf/Assertions.h>
+
namespace WebCore {
CrossThreadCopierBase<false, false, KURL>::Type CrossThreadCopierBase<false, false, KURL>::copy(const KURL& url)
@@ -66,4 +68,68 @@
return response.copyData();
}
+// Test CrossThreadCopier using COMPILE_ASSERT.
+
+// Verify that ThreadSafeRefCounted objects get handled correctly.
+class CopierThreadSafeRefCountedTest : public ThreadSafeRefCounted<CopierThreadSafeRefCountedTest> {
+};
+
+COMPILE_ASSERT((WTF::IsSameType<
+ PassRefPtr<CopierThreadSafeRefCountedTest>,
+ CrossThreadCopier<PassRefPtr<CopierThreadSafeRefCountedTest> >::Type
+ >::value),
+ PassRefPtrTest);
+COMPILE_ASSERT((WTF::IsSameType<
+ PassRefPtr<CopierThreadSafeRefCountedTest>,
+ CrossThreadCopier<RefPtr<CopierThreadSafeRefCountedTest> >::Type
+ >::value),
+ RefPtrTest);
+COMPILE_ASSERT((WTF::IsSameType<
+ PassRefPtr<CopierThreadSafeRefCountedTest>,
+ CrossThreadCopier<CopierThreadSafeRefCountedTest*>::Type
+ >::value),
+ RawPointerTest);
+
+
+// Add a generic specialization which will let's us verify that no other template matches.
+template<typename T> struct CrossThreadCopierBase<false, false, T> {
+ typedef int Type;
+};
+
+// Verify that RefCounted objects only match our generic template which exposes Type as int.
+class CopierRefCountedTest : public RefCounted<CopierRefCountedTest> {
+};
+
+COMPILE_ASSERT((WTF::IsSameType<
+ int,
+ CrossThreadCopier<PassRefPtr<CopierRefCountedTest> >::Type
+ >::value),
+ PassRefPtrRefCountedTest);
+
+COMPILE_ASSERT((WTF::IsSameType<
+ int,
+ CrossThreadCopier<RefPtr<CopierRefCountedTest> >::Type
+ >::value),
+ RefPtrRefCountedTest);
+
+COMPILE_ASSERT((WTF::IsSameType<
+ int,
+ CrossThreadCopier<CopierRefCountedTest*>::Type
+ >::value),
+ RawPointerRefCountedTest);
+
+// Verify that PassOwnPtr gets passed through.
+COMPILE_ASSERT((WTF::IsSameType<
+ PassOwnPtr<float>,
+ CrossThreadCopier<PassOwnPtr<float> >::Type
+ >::value),
+ PassOwnPtrTest);
+
+// Verify that PassOwnPtr does not get passed through.
+COMPILE_ASSERT((WTF::IsSameType<
+ int,
+ CrossThreadCopier<OwnPtr<float> >::Type
+ >::value),
+ OwnPtrTest);
+
} // namespace WebCore
Modified: trunk/Source/WebCore/platform/CrossThreadCopier.h (94985 => 94986)
--- trunk/Source/WebCore/platform/CrossThreadCopier.h 2011-09-12 22:43:51 UTC (rev 94985)
+++ trunk/Source/WebCore/platform/CrossThreadCopier.h 2011-09-12 22:48:38 UTC (rev 94986)
@@ -31,6 +31,7 @@
#ifndef CrossThreadCopier_h
#define CrossThreadCopier_h
+#include <wtf/Assertions.h>
#include <wtf/Forward.h>
#include <wtf/PassOwnPtr.h>
#include <wtf/PassRefPtr.h>
@@ -68,11 +69,19 @@
// Custom copy methods.
template<typename T> struct CrossThreadCopierBase<false, true, T> {
typedef typename WTF::RemoveTemplate<T, RefPtr>::Type TypeWithoutRefPtr;
- typedef typename WTF::RemoveTemplate<TypeWithoutRefPtr, PassRefPtr>::Type RefCountedType;
+ typedef typename WTF::RemoveTemplate<TypeWithoutRefPtr, PassRefPtr>::Type TypeWithoutPassRefPtr;
+ typedef typename WTF::RemovePointer<TypeWithoutPassRefPtr>::Type RefCountedType;
+
+ // Verify that only one of the above did a change.
+ COMPILE_ASSERT((WTF::IsSameType<RefPtr<RefCountedType>, T>::value
+ || WTF::IsSameType<PassRefPtr<RefCountedType>, T>::value
+ || WTF::IsSameType<RefCountedType*, T>::value),
+ OnlyAllowOneTypeModification);
+
typedef PassRefPtr<RefCountedType> Type;
static Type copy(const T& refPtr)
{
- return refPtr.get();
+ return refPtr;
}
};
@@ -111,6 +120,7 @@
template<typename T> struct CrossThreadCopier : public CrossThreadCopierBase<WTF::IsConvertibleToInteger<T>::value,
WTF::IsSubclassOfTemplate<typename WTF::RemoveTemplate<T, RefPtr>::Type, ThreadSafeRefCounted>::value
+ || WTF::IsSubclassOfTemplate<typename WTF::RemovePointer<T>::Type, ThreadSafeRefCounted>::value
|| WTF::IsSubclassOfTemplate<typename WTF::RemoveTemplate<T, PassRefPtr>::Type, ThreadSafeRefCounted>::value,
T> {
};