| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 BASE_TASK_SCHEDULER_POST_TASK_H_ | 5 #ifndef BASE_TASK_SCHEDULER_POST_TASK_H_ |
| 6 #define BASE_TASK_SCHEDULER_POST_TASK_H_ | 6 #define BASE_TASK_SCHEDULER_POST_TASK_H_ |
| 7 | 7 |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/base_export.h" | 10 #include "base/base_export.h" |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/location.h" | 13 #include "base/location.h" |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/post_task_and_reply_with_result_internal.h" | 15 #include "base/post_task_and_reply_with_result_internal.h" |
| 16 #include "base/sequenced_task_runner.h" | 16 #include "base/sequenced_task_runner.h" |
| 17 #include "base/single_thread_task_runner.h" | 17 #include "base/single_thread_task_runner.h" |
| 18 #include "base/task_runner.h" | 18 #include "base/task_runner.h" |
| 19 #include "base/task_scheduler/single_thread_task_runner_thread_mode.h" |
| 19 #include "base/task_scheduler/task_traits.h" | 20 #include "base/task_scheduler/task_traits.h" |
| 20 #include "base/time/time.h" | 21 #include "base/time/time.h" |
| 21 #include "build/build_config.h" | 22 #include "build/build_config.h" |
| 22 | 23 |
| 23 namespace base { | 24 namespace base { |
| 24 | 25 |
| 25 // This is the preferred interface to post tasks to the TaskScheduler. | 26 // This is the preferred interface to post tasks to the TaskScheduler. |
| 26 // | 27 // |
| 27 // To post a simple one-off task with default traits: | 28 // To post a simple one-off task with default traits: |
| 28 // PostTask(FROM_HERE, Bind(...)); | 29 // PostTask(FROM_HERE, Bind(...)); |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 // using |traits|. Tasks may run in any order and in parallel. | 184 // using |traits|. Tasks may run in any order and in parallel. |
| 184 BASE_EXPORT scoped_refptr<TaskRunner> CreateTaskRunnerWithTraits( | 185 BASE_EXPORT scoped_refptr<TaskRunner> CreateTaskRunnerWithTraits( |
| 185 const TaskTraits& traits); | 186 const TaskTraits& traits); |
| 186 | 187 |
| 187 // Returns a SequencedTaskRunner whose PostTask invocations result in scheduling | 188 // Returns a SequencedTaskRunner whose PostTask invocations result in scheduling |
| 188 // tasks using |traits|. Tasks run one at a time in posting order. | 189 // tasks using |traits|. Tasks run one at a time in posting order. |
| 189 BASE_EXPORT scoped_refptr<SequencedTaskRunner> | 190 BASE_EXPORT scoped_refptr<SequencedTaskRunner> |
| 190 CreateSequencedTaskRunnerWithTraits(const TaskTraits& traits); | 191 CreateSequencedTaskRunnerWithTraits(const TaskTraits& traits); |
| 191 | 192 |
| 192 // Returns a SingleThreadTaskRunner whose PostTask invocations result in | 193 // Returns a SingleThreadTaskRunner whose PostTask invocations result in |
| 193 // scheduling tasks using |traits|. Tasks run on a single thread in posting | 194 // scheduling tasks using |traits| on a thread determined by |thread_mode|. See |
| 194 // order. | 195 // base/task_scheduler/single_thread_task_runner_thread_mode.h for |thread_mode| |
| 196 // details. Tasks run on a single thread in posting order. |
| 195 // | 197 // |
| 196 // If all you need is to make sure that tasks don't run concurrently (e.g. | 198 // If all you need is to make sure that tasks don't run concurrently (e.g. |
| 197 // because they access a data structure which is not thread-safe), use | 199 // because they access a data structure which is not thread-safe), use |
| 198 // CreateSequencedTaskRunnerWithTraits(). Only use this if you rely on a thread- | 200 // CreateSequencedTaskRunnerWithTraits(). Only use this if you rely on a thread- |
| 199 // affine API (it might be safer to assume thread-affinity when dealing with | 201 // affine API (it might be safer to assume thread-affinity when dealing with |
| 200 // under-documented third-party APIs, e.g. other OS') or share data across tasks | 202 // under-documented third-party APIs, e.g. other OS') or share data across tasks |
| 201 // using thread-local storage. | 203 // using thread-local storage. |
| 202 BASE_EXPORT scoped_refptr<SingleThreadTaskRunner> | 204 BASE_EXPORT scoped_refptr<SingleThreadTaskRunner> |
| 203 CreateSingleThreadTaskRunnerWithTraits(const TaskTraits& traits); | 205 CreateSingleThreadTaskRunnerWithTraits( |
| 206 const TaskTraits& traits, |
| 207 SingleThreadTaskRunnerThreadMode thread_mode = |
| 208 SingleThreadTaskRunnerThreadMode::SHARED); |
| 204 | 209 |
| 205 #if defined(OS_WIN) | 210 #if defined(OS_WIN) |
| 206 // Returns a SingleThreadTaskRunner whose PostTask invocations result in | 211 // Returns a SingleThreadTaskRunner whose PostTask invocations result in |
| 207 // scheduling tasks using |traits| in a COM Single-Threaded Apartment. Tasks run | 212 // scheduling tasks using |traits| in a COM Single-Threaded Apartment on a |
| 208 // in the same Single-Threaded Apartment in posting order for the returned | 213 // thread determined by |thread_mode|. See |
| 209 // SingleThreadTaskRunner. There is not necessarily a one-to-one correspondence | 214 // base/task_scheduler/single_thread_task_runner_thread_mode.h for |thread_mode| |
| 210 // between SingleThreadTaskRunners and Single-Threaded Apartments. The | 215 // details. Tasks run in the same Single-Threaded Apartment in posting order for |
| 211 // implementation is free to share apartments or create new apartments as | 216 // the returned SingleThreadTaskRunner. There is not necessarily a one-to-one |
| 212 // necessary. In either case, care should be taken to make sure COM pointers are | 217 // correspondence between SingleThreadTaskRunners and Single-Threaded |
| 213 // not smuggled across apartments. | 218 // Apartments. The implementation is free to share apartments or create new |
| 219 // apartments as necessary. In either case, care should be taken to make sure |
| 220 // COM pointers are not smuggled across apartments. |
| 214 BASE_EXPORT scoped_refptr<SingleThreadTaskRunner> | 221 BASE_EXPORT scoped_refptr<SingleThreadTaskRunner> |
| 215 CreateCOMSTATaskRunnerWithTraits(const TaskTraits& traits); | 222 CreateCOMSTATaskRunnerWithTraits(const TaskTraits& traits, |
| 223 SingleThreadTaskRunnerThreadMode thread_mode = |
| 224 SingleThreadTaskRunnerThreadMode::SHARED); |
| 216 #endif // defined(OS_WIN) | 225 #endif // defined(OS_WIN) |
| 217 | 226 |
| 218 } // namespace base | 227 } // namespace base |
| 219 | 228 |
| 220 #endif // BASE_TASK_SCHEDULER_POST_TASK_H_ | 229 #endif // BASE_TASK_SCHEDULER_POST_TASK_H_ |
| OLD | NEW |