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 #include "base/task_scheduler/task_tracker.h" | 5 #include "base/task_scheduler/task_tracker.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/atomicops.h" | 9 #include "base/atomicops.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/debug/task_annotator.h" | 11 #include "base/debug/task_annotator.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/metrics/histogram_macros.h" | 13 #include "base/metrics/histogram_macros.h" |
| 14 #include "base/sequence_token.h" |
14 #include "base/threading/sequenced_task_runner_handle.h" | 15 #include "base/threading/sequenced_task_runner_handle.h" |
15 #include "base/threading/thread_restrictions.h" | 16 #include "base/threading/thread_restrictions.h" |
16 #include "base/threading/thread_task_runner_handle.h" | 17 #include "base/threading/thread_task_runner_handle.h" |
17 #include "base/trace_event/trace_event.h" | 18 #include "base/trace_event/trace_event.h" |
18 | 19 |
19 namespace base { | 20 namespace base { |
20 namespace internal { | 21 namespace internal { |
21 | 22 |
22 namespace { | 23 namespace { |
23 | 24 |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 | 171 |
171 if (!BeforePostTask(task->traits.shutdown_behavior())) | 172 if (!BeforePostTask(task->traits.shutdown_behavior())) |
172 return false; | 173 return false; |
173 | 174 |
174 debug::TaskAnnotator task_annotator; | 175 debug::TaskAnnotator task_annotator; |
175 task_annotator.DidQueueTask(kQueueFunctionName, *task); | 176 task_annotator.DidQueueTask(kQueueFunctionName, *task); |
176 | 177 |
177 return true; | 178 return true; |
178 } | 179 } |
179 | 180 |
180 void TaskTracker::RunTask(const Task* task) { | 181 void TaskTracker::RunNextTaskInSequence(const Sequence* sequence) { |
181 DCHECK(task); | 182 DCHECK(sequence); |
| 183 DCHECK(sequence->PeekTask()); |
| 184 |
| 185 const Task* task = sequence->PeekTask(); |
182 | 186 |
183 const TaskShutdownBehavior shutdown_behavior = | 187 const TaskShutdownBehavior shutdown_behavior = |
184 task->traits.shutdown_behavior(); | 188 task->traits.shutdown_behavior(); |
185 if (!BeforeRunTask(shutdown_behavior)) | 189 if (!BeforeRunTask(shutdown_behavior)) |
186 return; | 190 return; |
187 | 191 |
188 // All tasks run through here and the scheduler itself doesn't use singletons. | 192 // All tasks run through here and the scheduler itself doesn't use singletons. |
189 // Therefore, it isn't necessary to reset the singleton allowed bit after | 193 // Therefore, it isn't necessary to reset the singleton allowed bit after |
190 // running the task. | 194 // running the task. |
191 ThreadRestrictions::SetSingletonAllowed( | 195 ThreadRestrictions::SetSingletonAllowed( |
192 task->traits.shutdown_behavior() != | 196 task->traits.shutdown_behavior() != |
193 TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN); | 197 TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN); |
194 | 198 |
195 { | 199 { |
| 200 // Set up SequenceToken as expected for the scope of the task. |
| 201 ScopedSetSequenceTokenForCurrentThread |
| 202 scoped_set_sequence_token_for_current_thread(sequence->token()); |
| 203 |
196 // Set up TaskRunnerHandle as expected for the scope of the task. | 204 // Set up TaskRunnerHandle as expected for the scope of the task. |
197 std::unique_ptr<SequencedTaskRunnerHandle> sequenced_task_runner_handle; | 205 std::unique_ptr<SequencedTaskRunnerHandle> sequenced_task_runner_handle; |
198 std::unique_ptr<ThreadTaskRunnerHandle> single_thread_task_runner_handle; | 206 std::unique_ptr<ThreadTaskRunnerHandle> single_thread_task_runner_handle; |
199 DCHECK(!task->sequenced_task_runner_ref || | 207 DCHECK(!task->sequenced_task_runner_ref || |
200 !task->single_thread_task_runner_ref); | 208 !task->single_thread_task_runner_ref); |
201 if (task->sequenced_task_runner_ref) { | 209 if (task->sequenced_task_runner_ref) { |
202 sequenced_task_runner_handle.reset( | 210 sequenced_task_runner_handle.reset( |
203 new SequencedTaskRunnerHandle(task->sequenced_task_runner_ref)); | 211 new SequencedTaskRunnerHandle(task->sequenced_task_runner_ref)); |
204 } else if (task->single_thread_task_runner_ref) { | 212 } else if (task->single_thread_task_runner_ref) { |
205 single_thread_task_runner_handle.reset( | 213 single_thread_task_runner_handle.reset( |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 | 330 |
323 // This method can only be called after shutdown has started. | 331 // This method can only be called after shutdown has started. |
324 DCHECK(state_->HasShutdownStarted()); | 332 DCHECK(state_->HasShutdownStarted()); |
325 DCHECK(shutdown_event_); | 333 DCHECK(shutdown_event_); |
326 | 334 |
327 shutdown_event_->Signal(); | 335 shutdown_event_->Signal(); |
328 } | 336 } |
329 | 337 |
330 } // namespace internal | 338 } // namespace internal |
331 } // namespace base | 339 } // namespace base |
OLD | NEW |