| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Neither the name of Google Inc. nor the names of its | 10 * * Neither the name of Google Inc. nor the names of its |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 // createSameThreadTask. | 94 // createSameThreadTask. |
| 95 // See http://crbug.com/390851 | 95 // See http://crbug.com/390851 |
| 96 template <typename T, WTF::FunctionThreadAffinity threadAffinity> | 96 template <typename T, WTF::FunctionThreadAffinity threadAffinity> |
| 97 std::unique_ptr<CallClosureTask<T, threadAffinity>> createCallClosureTask( | 97 std::unique_ptr<CallClosureTask<T, threadAffinity>> createCallClosureTask( |
| 98 std::unique_ptr<Function<T, threadAffinity>> closure) { | 98 std::unique_ptr<Function<T, threadAffinity>> closure) { |
| 99 return CallClosureTask<T, threadAffinity>::create(std::move(closure)); | 99 return CallClosureTask<T, threadAffinity>::create(std::move(closure)); |
| 100 } | 100 } |
| 101 | 101 |
| 102 } // namespace internal | 102 } // namespace internal |
| 103 | 103 |
| 104 // Create tasks passed within a single thread. | 104 // createSameThreadTask() is deprecated and removed. |
| 105 // When posting tasks within a thread, use |createSameThreadTask| instead | 105 // Use WTF::bind() and post it to WebTaskRunner obtained by |
| 106 // of using |bind| directly to state explicitly that there is no need to care | 106 // TaskRunnerHelper::get() when posting a task within a single thread. |
| 107 // about thread safety when posting the task. | |
| 108 // When posting tasks across threads, use |createCrossThreadTask|. | |
| 109 template <typename FunctionType, typename... P> | |
| 110 std::unique_ptr<ExecutionContextTask> createSameThreadTask( | |
| 111 FunctionType function, | |
| 112 P&&... parameters) { | |
| 113 return internal::createCallClosureTask( | |
| 114 WTF::bind(function, std::forward<P>(parameters)...)); | |
| 115 } | |
| 116 | 107 |
| 108 // createCrossThreadTask() is deprecated and will be removed. |
| 109 // Use crossThreadBind() and post it to an appropriate task runner |
| 110 // when posting a task to another thread. |
| 111 // See https://crbug.com/625927 for details. |
| 112 // |
| 117 // createCrossThreadTask(...) is ExecutionContextTask version of | 113 // createCrossThreadTask(...) is ExecutionContextTask version of |
| 118 // crossThreadBind(). | 114 // crossThreadBind(). |
| 119 // Using WTF::bind() directly is not thread-safe due to temporary objects, see | 115 // Using WTF::bind() directly is not thread-safe due to temporary objects, see |
| 120 // https://crbug.com/390851 for details. | 116 // https://crbug.com/390851 for details. |
| 121 // | 117 // |
| 122 // Example: | 118 // Example: |
| 123 // void func1(int, const String&); | 119 // void func1(int, const String&); |
| 124 // createCrossThreadTask(func1, 42, str); | 120 // createCrossThreadTask(func1, 42, str); |
| 125 // func1(42, str2) will be called, where |str2| is a deep copy of | 121 // func1(42, str2) will be called, where |str2| is a deep copy of |
| 126 // |str| (created by str.isolatedCopy()). | 122 // |str| (created by str.isolatedCopy()). |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 std::unique_ptr<ExecutionContextTask> createCrossThreadTask( | 158 std::unique_ptr<ExecutionContextTask> createCrossThreadTask( |
| 163 FunctionType function, | 159 FunctionType function, |
| 164 P&&... parameters) { | 160 P&&... parameters) { |
| 165 return internal::createCallClosureTask( | 161 return internal::createCallClosureTask( |
| 166 crossThreadBind(function, std::forward<P>(parameters)...)); | 162 crossThreadBind(function, std::forward<P>(parameters)...)); |
| 167 } | 163 } |
| 168 | 164 |
| 169 } // namespace blink | 165 } // namespace blink |
| 170 | 166 |
| 171 #endif | 167 #endif |
| OLD | NEW |