Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(976)

Unified Diff: third_party/WebKit/Source/wtf/Functional.h

Issue 2123183002: Move crossThreadBind() from platform/ to wtf/ Base URL: https://chromium.googlesource.com/chromium/src.git@TRV_WTFCrossThreadCopier
Patch Set: Rebase Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/web/tests/SpinLockTest.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/wtf/Functional.h
diff --git a/third_party/WebKit/Source/wtf/Functional.h b/third_party/WebKit/Source/wtf/Functional.h
index 34f721557c687bf5fb58009f24ec7e367afb56dc..bdcff7c12602e8cfd6f35a9fb937b235663cc1e4 100644
--- a/third_party/WebKit/Source/wtf/Functional.h
+++ b/third_party/WebKit/Source/wtf/Functional.h
@@ -61,8 +61,19 @@ namespace WTF {
// WTF::bind() and WTF::Closure should be used for same-thread closures
// only, i.e. the closures must be created, executed and destructed on
// the same thread.
-// Use crossThreadBind() and CrossThreadClosure if the function/task is called
-// or destructed on a (potentially) different thread from the current thread.
+//
+// Use WTF::crossThreadBind() and WTF::CrossThreadClosure if the function/task
+// is called or destructed on a (potentially) different thread from the current
+// thread.
+// WTF::crossThreadBind() applies CrossThreadCopier to the arguments.
+// Example:
+// void func1(int, const String&);
+// f = crossThreadBind(func1, 42, str);
+// func1(42, str2) will be called when |f()| is executed,
+// where |str2| is a deep copy of |str| (created by str.isolatedCopy()).
+// Don't (if you pass the task across threads):
+// bind(func1, 42, str);
+// bind(func1, 42, str.isolatedCopy());
// WTF::bind() and move semantics
// ==============================
@@ -269,11 +280,19 @@ std::unique_ptr<Function<base::MakeUnboundRunType<FunctionType, BoundParameters.
return bindInternal<SameThreadAffinity>(function, std::forward<BoundParameters>(boundParameters)...);
}
+template <typename FunctionType, typename... BoundParameters>
+std::unique_ptr<Function<base::MakeUnboundRunType<FunctionType, BoundParameters...>, CrossThreadAffinity>> crossThreadBind(FunctionType function, BoundParameters&&... boundParameters)
+{
+ return bindInternal<CrossThreadAffinity>(function, CrossThreadCopier<typename std::decay<BoundParameters>::type>::copy(std::forward<BoundParameters>(boundParameters))...);
+}
+
typedef Function<void(), SameThreadAffinity> Closure;
typedef Function<void(), CrossThreadAffinity> CrossThreadClosure;
} // namespace WTF
+using WTF::crossThreadBind;
+
using WTF::passed;
using WTF::unretained;
using WTF::crossThreadUnretained;
« no previous file with comments | « third_party/WebKit/Source/web/tests/SpinLockTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698