| OLD | NEW |
| 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 Loading... |
| 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 |
| OLD | NEW |