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

Side by Side Diff: Source/platform/ThreadSafeFunctional.h

Issue 1091333003: Add comments about threadSafeBind() (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 8 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 unified diff | Download patch
« no previous file with comments | « no previous file | Source/wtf/Functional.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef ThreadSafeFunctional_h 5 #ifndef ThreadSafeFunctional_h
6 #define ThreadSafeFunctional_h 6 #define ThreadSafeFunctional_h
7 7
8 #include "platform/CrossThreadCopier.h" 8 #include "platform/CrossThreadCopier.h"
9 #include "wtf/Functional.h" 9 #include "wtf/Functional.h"
10 10
11 namespace blink { 11 namespace blink {
12 12
13 // threadSafeBind() is bind() for cross-thread task posting.
14 // threadSafeBind() applies CrossThreadCopier to the arguments.
15 //
16 // Example:
17 // void func1(int, const String&);
18 // f = threadSafeBind(func1, 42, str);
19 // func1(42, str2) will be called when |f()| is executed,
20 // where |str2| is a deep copy of |str| (created by str.isolatedCopy()).
21 //
22 // threadSafeBind(str) is similar to bind(str.isolatedCopy()), but the latter
23 // is NOT thread-safe due to temporary objects (https://crbug.com/390851).
24 //
25 // Don't (if you pass the task across threads):
26 // bind(func1, 42, str);
27 // bind(func1, 42, str.isolatedCopy());
28
13 template<typename... FreeVariableTypes, typename FunctionType> 29 template<typename... FreeVariableTypes, typename FunctionType>
14 PassOwnPtr<Function<typename WTF::FunctionWrapper<FunctionType>::ResultType(Free VariableTypes...)>> threadSafeBind( 30 PassOwnPtr<Function<typename WTF::FunctionWrapper<FunctionType>::ResultType(Free VariableTypes...)>> threadSafeBind(
15 FunctionType function) 31 FunctionType function)
16 { 32 {
17 return bind<FreeVariableTypes...>(function); 33 return bind<FreeVariableTypes...>(function);
18 } 34 }
19 35
20 template<typename... FreeVariableTypes, typename FunctionType, typename P1> 36 template<typename... FreeVariableTypes, typename FunctionType, typename P1>
21 PassOwnPtr<Function<typename WTF::FunctionWrapper<FunctionType>::ResultType(Free VariableTypes...)>> threadSafeBind( 37 PassOwnPtr<Function<typename WTF::FunctionWrapper<FunctionType>::ResultType(Free VariableTypes...)>> threadSafeBind(
22 FunctionType function, 38 FunctionType function,
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 CrossThreadCopier<P2>::copy(parameter2), 98 CrossThreadCopier<P2>::copy(parameter2),
83 CrossThreadCopier<P3>::copy(parameter3), 99 CrossThreadCopier<P3>::copy(parameter3),
84 CrossThreadCopier<P4>::copy(parameter4), 100 CrossThreadCopier<P4>::copy(parameter4),
85 CrossThreadCopier<P5>::copy(parameter5), 101 CrossThreadCopier<P5>::copy(parameter5),
86 CrossThreadCopier<P6>::copy(parameter6)); 102 CrossThreadCopier<P6>::copy(parameter6));
87 } 103 }
88 104
89 } // namespace blink 105 } // namespace blink
90 106
91 #endif // ThreadSafeFunctional_h 107 #endif // ThreadSafeFunctional_h
OLDNEW
« no previous file with comments | « no previous file | Source/wtf/Functional.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698