WebKit Bugzilla
Attachment 372422 Details for
Bug 198957
: Add WTF::crossThreadCopy(T&&) to utilize String::isolatedCopy() &&
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch for landing
bug-198957-20190619122816.patch (text/plain), 12.06 KB, created by
Fujii Hironori
on 2019-06-18 20:28:18 PDT
(
hide
)
Description:
Patch for landing
Filename:
MIME Type:
Creator:
Fujii Hironori
Created:
2019-06-18 20:28:18 PDT
Size:
12.06 KB
patch
obsolete
>Subversion Revision: 246534 >diff --git a/Source/WTF/ChangeLog b/Source/WTF/ChangeLog >index 26049362030fffd6844826caf0a515196859132b..f103a6b9d2a29fbff54915028f1b909f982e4ad4 100644 >--- a/Source/WTF/ChangeLog >+++ b/Source/WTF/ChangeLog >@@ -1,3 +1,23 @@ >+2019-06-18 Fujii Hironori <Hironori.Fujii@sony.com> >+ >+ Add WTF::crossThreadCopy(T&&) to utilize String::isolatedCopy() && >+ https://bugs.webkit.org/show_bug.cgi?id=198957 >+ >+ Reviewed by Alex Christensen. >+ >+ &&-qualified String::isolatedCopy() has a optimization path which >+ does just WTFMove if it isSafeToSendToAnotherThread which means >+ the object hasOneRef. >+ >+ However, WTF::crossThreadCopy was using only &-qualified >+ isolatedCopy. To use the optimization, added >+ WTF::crossThreadCopy(T&&) overloading. >+ >+ * wtf/CrossThreadCopier.h: >+ (WTF::crossThreadCopy): Added a overload of (T&&). >+ * wtf/CrossThreadTask.h: >+ (WTF::createCrossThreadTask): Removed explicit template arguments of crossThreadCopy. >+ > 2019-06-17 Jiewen Tan <jiewen_tan@apple.com> > > Move SOAuthorization from WebKitAdditions to WebKit >diff --git a/Source/WTF/wtf/CrossThreadCopier.h b/Source/WTF/wtf/CrossThreadCopier.h >index 633878ae938869db3b315471020897bca079f0c6..307ccaa6d6ff8e7b856ccc7762e03c41881b738d 100644 >--- a/Source/WTF/wtf/CrossThreadCopier.h >+++ b/Source/WTF/wtf/CrossThreadCopier.h >@@ -31,6 +31,7 @@ > > #pragma once > >+#include <type_traits> > #include <wtf/Assertions.h> > #include <wtf/Forward.h> > #include <wtf/HashSet.h> >@@ -77,9 +78,9 @@ template<typename T> struct CrossThreadCopierBase<true, false, T> : public Cross > > // Classes that have an isolatedCopy() method get a default specialization. > template<class T> struct CrossThreadCopierBase<false, false, T> { >- static T copy(const T& value) >+ template<typename U> static auto copy(U&& value) > { >- return value.isolatedCopy(); >+ return std::forward<U>(value).isolatedCopy(); > } > }; > >@@ -146,18 +147,17 @@ template<typename K, typename V> struct CrossThreadCopierBase<false, false, Hash > > // Default specialization for Optional of CrossThreadCopyable class. > template<typename T> struct CrossThreadCopierBase<false, false, Optional<T>> { >- typedef Optional<T> Type; >- static Type copy(const Type& source) >+ template<typename U> static Optional<T> copy(U&& source) > { > if (!source) > return WTF::nullopt; >- return CrossThreadCopier<T>::copy(*source); >+ return CrossThreadCopier<T>::copy(std::forward<U>(source).value()); > } > }; > >-template<typename T> T crossThreadCopy(const T& source) >+template<typename T> auto crossThreadCopy(T&& source) > { >- return CrossThreadCopier<T>::copy(source); >+ return CrossThreadCopier<std::remove_cv_t<std::remove_reference_t<T>>>::copy(std::forward<T>(source)); > } > > } // namespace WTF >diff --git a/Source/WTF/wtf/CrossThreadTask.h b/Source/WTF/wtf/CrossThreadTask.h >index ec437748e65d6eb6dbc8d3e2e40dafd2b54d70e8..2982e0d9f7656569b9e6e075d1f8b220d4fa8fb9 100644 >--- a/Source/WTF/wtf/CrossThreadTask.h >+++ b/Source/WTF/wtf/CrossThreadTask.h >@@ -67,7 +67,7 @@ void callFunctionForCrossThreadTask(F function, ArgsTuple&& args) > template<typename... Parameters, typename... Arguments> > CrossThreadTask createCrossThreadTask(void (*method)(Parameters...), const Arguments&... arguments) > { >- return CrossThreadTask([method, arguments = std::make_tuple(crossThreadCopy<Arguments>(arguments)...)]() mutable { >+ return CrossThreadTask([method, arguments = std::make_tuple(crossThreadCopy(arguments)...)]() mutable { > callFunctionForCrossThreadTask(method, WTFMove(arguments)); > }); > } >@@ -87,7 +87,7 @@ void callMemberFunctionForCrossThreadTask(C* object, MF function, ArgsTuple&& ar > template<typename T, typename std::enable_if<std::is_base_of<ThreadSafeRefCounted<T>, T>::value, int>::type = 0, typename... Parameters, typename... Arguments> > CrossThreadTask createCrossThreadTask(T& callee, void (T::*method)(Parameters...), const Arguments&... arguments) > { >- return CrossThreadTask([callee = makeRefPtr(&callee), method, arguments = std::make_tuple(crossThreadCopy<Arguments>(arguments)...)]() mutable { >+ return CrossThreadTask([callee = makeRefPtr(&callee), method, arguments = std::make_tuple(crossThreadCopy(arguments)...)]() mutable { > callMemberFunctionForCrossThreadTask(callee.get(), method, WTFMove(arguments)); > }); > } >@@ -95,7 +95,7 @@ CrossThreadTask createCrossThreadTask(T& callee, void (T::*method)(Parameters... > template<typename T, typename std::enable_if<!std::is_base_of<ThreadSafeRefCounted<T>, T>::value, int>::type = 0, typename... Parameters, typename... Arguments> > CrossThreadTask createCrossThreadTask(T& callee, void (T::*method)(Parameters...), const Arguments&... arguments) > { >- return CrossThreadTask([callee = &callee, method, arguments = std::make_tuple(crossThreadCopy<Arguments>(arguments)...)]() mutable { >+ return CrossThreadTask([callee = &callee, method, arguments = std::make_tuple(crossThreadCopy(arguments)...)]() mutable { > callMemberFunctionForCrossThreadTask(callee, method, WTFMove(arguments)); > }); > } >diff --git a/Tools/ChangeLog b/Tools/ChangeLog >index 09cccc2467edeb892ac4b5b13a63f3638741f7f5..0f87952e2293b52af69c1c46b5e577477038f9f0 100644 >--- a/Tools/ChangeLog >+++ b/Tools/ChangeLog >@@ -1,3 +1,14 @@ >+2019-06-18 Fujii Hironori <Hironori.Fujii@sony.com> >+ >+ Add WTF::crossThreadCopy(T&&) to utilize String::isolatedCopy() && >+ https://bugs.webkit.org/show_bug.cgi?id=198957 >+ >+ Reviewed by Alex Christensen. >+ >+ * TestWebKitAPI/CMakeLists.txt: >+ * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: >+ * TestWebKitAPI/Tests/WTF/CrossThreadCopier.cpp: Added. >+ > 2019-06-18 Dan Bernstein <mitz@apple.com> > > Revert workaround for bug 198904 from run-webkit-archive >diff --git a/Tools/TestWebKitAPI/CMakeLists.txt b/Tools/TestWebKitAPI/CMakeLists.txt >index 7adb608eeaa611b66b1ed5074a5917d0a0df8548..619e78d39fddd10cde5b9778220a247e20ef6a0c 100644 >--- a/Tools/TestWebKitAPI/CMakeLists.txt >+++ b/Tools/TestWebKitAPI/CMakeLists.txt >@@ -30,6 +30,7 @@ set(TestWTF_SOURCES > Tests/WTF/CheckedArithmeticOperations.cpp > Tests/WTF/ConcurrentPtrHashSet.cpp > Tests/WTF/Condition.cpp >+ Tests/WTF/CrossThreadCopier.cpp > Tests/WTF/CrossThreadTask.cpp > Tests/WTF/DateMath.cpp > Tests/WTF/Deque.cpp >diff --git a/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj b/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj >index 864729a99db43355650ba417c99f468d32149750..5100f443b5ac8757ac809ceba31a4ccc75e19283 100644 >--- a/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj >+++ b/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj >@@ -1469,6 +1469,7 @@ > 26F52EB018288F0F0023D412 /* geolocationWatchPosition.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = geolocationWatchPosition.html; sourceTree = "<group>"; }; > 26F52EB118288F0F0023D412 /* geolocationWatchPositionWithHighAccuracy.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = geolocationWatchPositionWithHighAccuracy.html; sourceTree = "<group>"; }; > 26F6E1EF1ADC749B00DE696B /* DFAMinimizer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DFAMinimizer.cpp; sourceTree = "<group>"; }; >+ 278DE64B22B8D611004E0E7A /* CrossThreadCopier.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CrossThreadCopier.cpp; sourceTree = "<group>"; }; > 290A9BB51735DE8A00D71BBC /* CloseNewWindowInNavigationPolicyDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CloseNewWindowInNavigationPolicyDelegate.mm; sourceTree = "<group>"; }; > 290A9BB81735F42300D71BBC /* OpenNewWindow.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = OpenNewWindow.html; sourceTree = "<group>"; }; > 290F4274172A1FDE00939FF0 /* custom-protocol-sync-xhr.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "custom-protocol-sync-xhr.html"; sourceTree = "<group>"; }; >@@ -3397,6 +3398,7 @@ > A7A966DA140ECCC8005EF9B4 /* CheckedArithmeticOperations.cpp */, > 0F30CB5B1FCE1792004B5323 /* ConcurrentPtrHashSet.cpp */, > 0FEAE3671B7D19CB00CE17F2 /* Condition.cpp */, >+ 278DE64B22B8D611004E0E7A /* CrossThreadCopier.cpp */, > 51714EB91D087416004723C4 /* CrossThreadTask.cpp */, > 26A2C72E15E2E73C005B1A14 /* CString.cpp */, > 7AA021BA1AB09EA70052953F /* DateMath.cpp */, >diff --git a/Tools/TestWebKitAPI/Tests/WTF/CrossThreadCopier.cpp b/Tools/TestWebKitAPI/Tests/WTF/CrossThreadCopier.cpp >new file mode 100644 >index 0000000000000000000000000000000000000000..78632ecffd9b82aeacf64e66998f227fcbc7b79d >--- /dev/null >+++ b/Tools/TestWebKitAPI/Tests/WTF/CrossThreadCopier.cpp >@@ -0,0 +1,89 @@ >+/* >+ * Copyright (C) 2019 Sony Interactive Entertainment Inc. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' >+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, >+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR >+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS >+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF >+ * THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+#include "config.h" >+#include <wtf/CrossThreadCopier.h> >+ >+#include "Test.h" >+#include <wtf/Optional.h> >+#include <wtf/text/WTFString.h> >+ >+namespace TestWebKitAPI { >+ >+TEST(WTF_CrossThreadCopier, CopyLVString) >+{ >+ String original { "1234" }; >+ auto copy = crossThreadCopy(original); >+ EXPECT_TRUE(original.impl()->hasOneRef()); >+ EXPECT_TRUE(copy.impl()->hasOneRef()); >+ EXPECT_FALSE(original.impl() == copy.impl()); >+} >+ >+TEST(WTF_CrossThreadCopier, MoveRVString) >+{ >+ String original { "1234" }; >+ auto copy = crossThreadCopy(WTFMove(original)); >+ EXPECT_TRUE(copy.impl()->hasOneRef()); >+ EXPECT_NULL(original.impl()); >+} >+ >+TEST(WTF_CrossThreadCopier, CopyRVStringHavingTwoRef) >+{ >+ String original { "1234" }; >+ String original2 { original }; >+ auto copy = crossThreadCopy(WTFMove(original)); >+ EXPECT_EQ(original.impl()->refCount(), 2); >+ EXPECT_FALSE(original.impl() == copy.impl()); >+ EXPECT_TRUE(copy.impl()->hasOneRef()); >+} >+ >+TEST(WTF_CrossThreadCopier, CopyLVOptionalString) >+{ >+ Optional<String> original { "1234" }; >+ auto copy = crossThreadCopy(original); >+ EXPECT_TRUE(original->impl()->hasOneRef()); >+ EXPECT_TRUE(copy->impl()->hasOneRef()); >+ EXPECT_FALSE(original->impl() == copy->impl()); >+} >+ >+TEST(WTF_CrossThreadCopier, MoveRVOptionalString) >+{ >+ Optional<String> original { "1234" }; >+ auto copy = crossThreadCopy(WTFMove(original)); >+ EXPECT_TRUE(copy->impl()->hasOneRef()); >+ EXPECT_NULL(original->impl()); >+} >+ >+TEST(WTF_CrossThreadCopier, CopyRVOptionalStringHavingTwoRef) >+{ >+ String string { "1234" }; >+ Optional<String> original { string }; >+ auto copy = crossThreadCopy(original); >+ EXPECT_EQ(original->impl()->refCount(), 2); >+ EXPECT_FALSE(original->impl() == copy->impl()); >+ EXPECT_TRUE(copy->impl()->hasOneRef()); >+} >+ >+} // namespace TestWebKitAPI
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 198957
:
372330
|
372332
| 372422