Chromium Code Reviews| 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/task_traits.h" | 19 #include "base/task_scheduler/task_traits.h" |
| 20 #include "base/time/time.h" | 20 #include "base/time/time.h" |
| 21 | 21 |
| 22 namespace base { | 22 namespace base { |
| 23 | 23 |
| 24 // This is the preferred interface to post tasks to the TaskScheduler. | 24 // This is the preferred interface to post tasks to the TaskScheduler. |
| 25 // | 25 // |
| 26 // TaskScheduler must have been registered for the current process via | |
| 27 // TaskScheduler::SetInstance() before the functions below are valid. | |
| 28 // | |
| 29 // To post a simple one-off task with default traits: | 26 // To post a simple one-off task with default traits: |
| 30 // PostTask(FROM_HERE, Bind(...)); | 27 // PostTask(FROM_HERE, Bind(...)); |
| 31 // | 28 // |
| 32 // To post a high priority one-off task to respond to a user interaction: | 29 // To post a high priority one-off task to respond to a user interaction: |
| 33 // PostTaskWithTraits( | 30 // PostTaskWithTraits( |
| 34 // FROM_HERE, | 31 // FROM_HERE, |
| 35 // TaskTraits().WithPriority(TaskPriority::USER_BLOCKING), | 32 // TaskTraits().WithPriority(TaskPriority::USER_BLOCKING), |
| 36 // Bind(...)); | 33 // Bind(...)); |
| 37 // | 34 // |
| 38 // To post tasks that must run in sequence with default traits: | 35 // To post tasks that must run in sequence with default traits: |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 55 // (2) prefer inheriting the current priority to specifying their own, and | 52 // (2) prefer inheriting the current priority to specifying their own, and |
| 56 // (3) can either block shutdown or be skipped on shutdown | 53 // (3) can either block shutdown or be skipped on shutdown |
| 57 // (TaskScheduler implementation is free to choose a fitting default). | 54 // (TaskScheduler implementation is free to choose a fitting default). |
| 58 // Explicit traits must be specified for tasks for which these loose | 55 // Explicit traits must be specified for tasks for which these loose |
| 59 // requirements are not sufficient. | 56 // requirements are not sufficient. |
| 60 // | 57 // |
| 61 // Tasks posted through functions below will run on threads owned by the | 58 // Tasks posted through functions below will run on threads owned by the |
| 62 // registered TaskScheduler (i.e. not on the main thread). Tasks posted through | 59 // registered TaskScheduler (i.e. not on the main thread). Tasks posted through |
| 63 // functions below with a delay may be coalesced (i.e. delays may be adjusted to | 60 // functions below with a delay may be coalesced (i.e. delays may be adjusted to |
| 64 // reduce the number of wakeups and hence power consumption). | 61 // reduce the number of wakeups and hence power consumption). |
| 62 // | |
| 63 // Prerequisite: A TaskScheduler must have been registered for the current | |
| 64 // process via TaskScheduler::SetInstance() before the functions below are | |
| 65 // valid. Note: this is typically done in the main of each process and you most | |
|
robliao
2017/02/23 23:00:33
Omit "Note:"
Maybe
This is typically done during
gab
2017/02/23 23:39:57
Done and also documented GetInstance() further to
| |
| 66 // likely don't have to worry about this if you're not in charge of the main for | |
| 67 // your process (the failure mode isn't subtle either -- DCHECK or nullptr | |
| 68 // crash -- so you'll find out quickly if this isn't the case). For tests, | |
| 69 // prefer base::test::ScopedTaskScheduler. | |
| 65 | 70 |
| 66 // Posts |task| to the TaskScheduler. Calling this is equivalent to calling | 71 // Posts |task| to the TaskScheduler. Calling this is equivalent to calling |
| 67 // PostTaskWithTraits with plain TaskTraits. | 72 // PostTaskWithTraits with plain TaskTraits. |
| 68 BASE_EXPORT void PostTask(const tracked_objects::Location& from_here, | 73 BASE_EXPORT void PostTask(const tracked_objects::Location& from_here, |
| 69 const Closure& task); | 74 const Closure& task); |
| 70 | 75 |
| 71 // Posts |task| to the TaskScheduler. |task| will not run before |delay| | 76 // Posts |task| to the TaskScheduler. |task| will not run before |delay| |
| 72 // expires. Calling this is equivalent to calling PostDelayedTaskWithTraits with | 77 // expires. Calling this is equivalent to calling PostDelayedTaskWithTraits with |
| 73 // plain TaskTraits. | 78 // plain TaskTraits. |
| 74 // | 79 // |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 163 // CreateSequencedTaskRunnerWithTraits(). Only use this if you rely on a thread- | 168 // CreateSequencedTaskRunnerWithTraits(). Only use this if you rely on a thread- |
| 164 // affine API (it might be safer to assume thread-affinity when dealing with | 169 // affine API (it might be safer to assume thread-affinity when dealing with |
| 165 // under-documented third-party APIs, e.g. other OS') or share data across tasks | 170 // under-documented third-party APIs, e.g. other OS') or share data across tasks |
| 166 // using thread-local storage. | 171 // using thread-local storage. |
| 167 BASE_EXPORT scoped_refptr<SingleThreadTaskRunner> | 172 BASE_EXPORT scoped_refptr<SingleThreadTaskRunner> |
| 168 CreateSingleThreadTaskRunnerWithTraits(const TaskTraits& traits); | 173 CreateSingleThreadTaskRunnerWithTraits(const TaskTraits& traits); |
| 169 | 174 |
| 170 } // namespace base | 175 } // namespace base |
| 171 | 176 |
| 172 #endif // BASE_TASK_SCHEDULER_POST_TASK_H_ | 177 #endif // BASE_TASK_SCHEDULER_POST_TASK_H_ |
| OLD | NEW |