| 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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 | 170 |
| 170 if (!BeforePostTask(task->traits.shutdown_behavior())) | 171 if (!BeforePostTask(task->traits.shutdown_behavior())) |
| 171 return false; | 172 return false; |
| 172 | 173 |
| 173 debug::TaskAnnotator task_annotator; | 174 debug::TaskAnnotator task_annotator; |
| 174 task_annotator.DidQueueTask(kQueueFunctionName, *task); | 175 task_annotator.DidQueueTask(kQueueFunctionName, *task); |
| 175 | 176 |
| 176 return true; | 177 return true; |
| 177 } | 178 } |
| 178 | 179 |
| 179 void TaskTracker::RunTask(const Task* task) { | 180 void TaskTracker::RunNextTaskInSequence(const Sequence* sequence) { |
| 180 DCHECK(task); | 181 DCHECK(sequence); |
| 182 DCHECK(sequence->PeekTask()); |
| 183 |
| 184 const Task* task = sequence->PeekTask(); |
| 181 | 185 |
| 182 const TaskShutdownBehavior shutdown_behavior = | 186 const TaskShutdownBehavior shutdown_behavior = |
| 183 task->traits.shutdown_behavior(); | 187 task->traits.shutdown_behavior(); |
| 184 if (!BeforeRunTask(shutdown_behavior)) | 188 if (!BeforeRunTask(shutdown_behavior)) |
| 185 return; | 189 return; |
| 186 | 190 |
| 187 // All tasks run through here and the scheduler itself doesn't use singletons. | 191 // All tasks run through here and the scheduler itself doesn't use singletons. |
| 188 // Therefore, it isn't necessary to reset the singleton allowed bit after | 192 // Therefore, it isn't necessary to reset the singleton allowed bit after |
| 189 // running the task. | 193 // running the task. |
| 190 ThreadRestrictions::SetSingletonAllowed( | 194 ThreadRestrictions::SetSingletonAllowed( |
| 191 task->traits.shutdown_behavior() != | 195 task->traits.shutdown_behavior() != |
| 192 TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN); | 196 TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN); |
| 193 | 197 |
| 194 { | 198 { |
| 199 // Set up SequenceToken as expected for the scope of the task. |
| 200 ScopedSetCurrentSequenceToken scoped_set_current_sequence_token( |
| 201 sequence->token()); |
| 202 |
| 195 // Set up TaskRunnerHandle as expected for the scope of the task. | 203 // Set up TaskRunnerHandle as expected for the scope of the task. |
| 196 std::unique_ptr<SequencedTaskRunnerHandle> sequenced_task_runner_handle; | 204 std::unique_ptr<SequencedTaskRunnerHandle> sequenced_task_runner_handle; |
| 197 std::unique_ptr<ThreadTaskRunnerHandle> single_thread_task_runner_handle; | 205 std::unique_ptr<ThreadTaskRunnerHandle> single_thread_task_runner_handle; |
| 198 DCHECK(!task->sequenced_task_runner_ref || | 206 DCHECK(!task->sequenced_task_runner_ref || |
| 199 !task->single_thread_task_runner_ref); | 207 !task->single_thread_task_runner_ref); |
| 200 if (task->sequenced_task_runner_ref) { | 208 if (task->sequenced_task_runner_ref) { |
| 201 sequenced_task_runner_handle.reset( | 209 sequenced_task_runner_handle.reset( |
| 202 new SequencedTaskRunnerHandle(task->sequenced_task_runner_ref)); | 210 new SequencedTaskRunnerHandle(task->sequenced_task_runner_ref)); |
| 203 } else if (task->single_thread_task_runner_ref) { | 211 } else if (task->single_thread_task_runner_ref) { |
| 204 single_thread_task_runner_handle.reset( | 212 single_thread_task_runner_handle.reset( |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 | 326 |
| 319 // This method can only be called after shutdown has started. | 327 // This method can only be called after shutdown has started. |
| 320 DCHECK(state_->HasShutdownStarted()); | 328 DCHECK(state_->HasShutdownStarted()); |
| 321 DCHECK(shutdown_event_); | 329 DCHECK(shutdown_event_); |
| 322 | 330 |
| 323 shutdown_event_->Signal(); | 331 shutdown_event_->Signal(); |
| 324 } | 332 } |
| 325 | 333 |
| 326 } // namespace internal | 334 } // namespace internal |
| 327 } // namespace base | 335 } // namespace base |
| OLD | NEW |