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" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 // Prerequisite: A TaskScheduler must have been registered for the current | 63 // Prerequisite: A TaskScheduler must have been registered for the current |
64 // process via TaskScheduler::SetInstance() before the functions below are | 64 // process via TaskScheduler::SetInstance() before the functions below are |
65 // valid. This is typically done during the initialization phase in each | 65 // valid. This is typically done during the initialization phase in each |
66 // process. If your code is not running in that phase, you most likely don't | 66 // process. If your code is not running in that phase, you most likely don't |
67 // have to worry about this. You will encounter DCHECKs or nullptr dereferences | 67 // have to worry about this. You will encounter DCHECKs or nullptr dereferences |
68 // if this is violated. For tests, prefer base::test::ScopedTaskScheduler. | 68 // if this is violated. For tests, prefer base::test::ScopedTaskScheduler. |
69 | 69 |
70 // Posts |task| to the TaskScheduler. Calling this is equivalent to calling | 70 // Posts |task| to the TaskScheduler. Calling this is equivalent to calling |
71 // PostTaskWithTraits with plain TaskTraits. | 71 // PostTaskWithTraits with plain TaskTraits. |
72 BASE_EXPORT void PostTask(const tracked_objects::Location& from_here, | 72 BASE_EXPORT void PostTask(const tracked_objects::Location& from_here, |
73 const Closure& task); | 73 Closure task); |
74 | 74 |
75 // Posts |task| to the TaskScheduler. |task| will not run before |delay| | 75 // Posts |task| to the TaskScheduler. |task| will not run before |delay| |
76 // expires. Calling this is equivalent to calling PostDelayedTaskWithTraits with | 76 // expires. Calling this is equivalent to calling PostDelayedTaskWithTraits with |
77 // plain TaskTraits. | 77 // plain TaskTraits. |
78 // | 78 // |
79 // Use PostDelayedTaskWithTraits to specify a BACKGROUND priority if the task | 79 // Use PostDelayedTaskWithTraits to specify a BACKGROUND priority if the task |
80 // doesn't have to run as soon as |delay| expires. | 80 // doesn't have to run as soon as |delay| expires. |
81 BASE_EXPORT void PostDelayedTask(const tracked_objects::Location& from_here, | 81 BASE_EXPORT void PostDelayedTask(const tracked_objects::Location& from_here, |
82 const Closure& task, | 82 Closure task, |
83 TimeDelta delay); | 83 TimeDelta delay); |
84 | 84 |
85 // Posts |task| to the TaskScheduler and posts |reply| on the caller's execution | 85 // Posts |task| to the TaskScheduler and posts |reply| on the caller's execution |
86 // context (i.e. same sequence or thread and same TaskTraits if applicable) when | 86 // context (i.e. same sequence or thread and same TaskTraits if applicable) when |
87 // |task| completes. Calling this is equivalent to calling | 87 // |task| completes. Calling this is equivalent to calling |
88 // PostTaskWithTraitsAndReply with plain TaskTraits. Can only be called when | 88 // PostTaskWithTraitsAndReply with plain TaskTraits. Can only be called when |
89 // SequencedTaskRunnerHandle::IsSet(). | 89 // SequencedTaskRunnerHandle::IsSet(). |
90 BASE_EXPORT void PostTaskAndReply(const tracked_objects::Location& from_here, | 90 BASE_EXPORT void PostTaskAndReply(const tracked_objects::Location& from_here, |
91 Closure task, | 91 Closure task, |
92 Closure reply); | 92 Closure reply); |
93 | 93 |
94 // Posts |task| to the TaskScheduler and posts |reply| with the return value of | 94 // Posts |task| to the TaskScheduler and posts |reply| with the return value of |
95 // |task| as argument on the caller's execution context (i.e. same sequence or | 95 // |task| as argument on the caller's execution context (i.e. same sequence or |
96 // thread and same TaskTraits if applicable) when |task| completes. Calling this | 96 // thread and same TaskTraits if applicable) when |task| completes. Calling this |
97 // is equivalent to calling PostTaskWithTraitsAndReplyWithResult with plain | 97 // is equivalent to calling PostTaskWithTraitsAndReplyWithResult with plain |
98 // TaskTraits. Can only be called when SequencedTaskRunnerHandle::IsSet(). | 98 // TaskTraits. Can only be called when SequencedTaskRunnerHandle::IsSet(). |
99 template <typename TaskReturnType, typename ReplyArgType> | 99 template <typename TaskReturnType, typename ReplyArgType> |
100 void PostTaskAndReplyWithResult(const tracked_objects::Location& from_here, | 100 void PostTaskAndReplyWithResult(const tracked_objects::Location& from_here, |
101 Callback<TaskReturnType(void)> task, | 101 Callback<TaskReturnType(void)> task, |
102 Callback<void(ReplyArgType)> reply) { | 102 Callback<void(ReplyArgType)> reply) { |
103 PostTaskWithTraitsAndReplyWithResult(from_here, TaskTraits(), std::move(task), | 103 PostTaskWithTraitsAndReplyWithResult(from_here, TaskTraits(), std::move(task), |
104 std::move(reply)); | 104 std::move(reply)); |
105 } | 105 } |
106 | 106 |
107 // Posts |task| with specific |traits| to the TaskScheduler. | 107 // Posts |task| with specific |traits| to the TaskScheduler. |
108 BASE_EXPORT void PostTaskWithTraits(const tracked_objects::Location& from_here, | 108 BASE_EXPORT void PostTaskWithTraits(const tracked_objects::Location& from_here, |
109 const TaskTraits& traits, | 109 const TaskTraits& traits, |
110 const Closure& task); | 110 Closure task); |
111 | 111 |
112 // Posts |task| with specific |traits| to the TaskScheduler. |task| will not run | 112 // Posts |task| with specific |traits| to the TaskScheduler. |task| will not run |
113 // before |delay| expires. | 113 // before |delay| expires. |
114 // | 114 // |
115 // Specify a BACKGROUND priority via |traits| if the task doesn't have to run as | 115 // Specify a BACKGROUND priority via |traits| if the task doesn't have to run as |
116 // soon as |delay| expires. | 116 // soon as |delay| expires. |
117 BASE_EXPORT void PostDelayedTaskWithTraits( | 117 BASE_EXPORT void PostDelayedTaskWithTraits( |
118 const tracked_objects::Location& from_here, | 118 const tracked_objects::Location& from_here, |
119 const TaskTraits& traits, | 119 const TaskTraits& traits, |
120 const Closure& task, | 120 Closure task, |
121 TimeDelta delay); | 121 TimeDelta delay); |
122 | 122 |
123 // Posts |task| with specific |traits| to the TaskScheduler and posts |reply| on | 123 // Posts |task| with specific |traits| to the TaskScheduler and posts |reply| on |
124 // the caller's execution context (i.e. same sequence or thread and same | 124 // the caller's execution context (i.e. same sequence or thread and same |
125 // TaskTraits if applicable) when |task| completes. Can only be called when | 125 // TaskTraits if applicable) when |task| completes. Can only be called when |
126 // SequencedTaskRunnerHandle::IsSet(). | 126 // SequencedTaskRunnerHandle::IsSet(). |
127 BASE_EXPORT void PostTaskWithTraitsAndReply( | 127 BASE_EXPORT void PostTaskWithTraitsAndReply( |
128 const tracked_objects::Location& from_here, | 128 const tracked_objects::Location& from_here, |
129 const TaskTraits& traits, | 129 const TaskTraits& traits, |
130 Closure task, | 130 Closure task, |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 // CreateSequencedTaskRunnerWithTraits(). Only use this if you rely on a thread- | 167 // CreateSequencedTaskRunnerWithTraits(). Only use this if you rely on a thread- |
168 // affine API (it might be safer to assume thread-affinity when dealing with | 168 // affine API (it might be safer to assume thread-affinity when dealing with |
169 // under-documented third-party APIs, e.g. other OS') or share data across tasks | 169 // under-documented third-party APIs, e.g. other OS') or share data across tasks |
170 // using thread-local storage. | 170 // using thread-local storage. |
171 BASE_EXPORT scoped_refptr<SingleThreadTaskRunner> | 171 BASE_EXPORT scoped_refptr<SingleThreadTaskRunner> |
172 CreateSingleThreadTaskRunnerWithTraits(const TaskTraits& traits); | 172 CreateSingleThreadTaskRunnerWithTraits(const TaskTraits& traits); |
173 | 173 |
174 } // namespace base | 174 } // namespace base |
175 | 175 |
176 #endif // BASE_TASK_SCHEDULER_POST_TASK_H_ | 176 #endif // BASE_TASK_SCHEDULER_POST_TASK_H_ |
OLD | NEW |