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 "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/debug/task_annotator.h" | 8 #include "base/debug/task_annotator.h" |
9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
| 10 #include "base/thread_task_runner_handle.h" |
| 11 #include "base/threading/sequenced_task_runner_handle.h" |
10 #include "base/threading/thread_restrictions.h" | 12 #include "base/threading/thread_restrictions.h" |
11 | 13 |
12 namespace base { | 14 namespace base { |
13 namespace internal { | 15 namespace internal { |
14 | 16 |
15 namespace { | 17 namespace { |
16 | 18 |
17 const char kQueueFunctionName[] = "base::PostTask"; | 19 const char kQueueFunctionName[] = "base::PostTask"; |
18 | 20 |
19 // Upper bound for the | 21 // Upper bound for the |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 if (!BeforeRunTask(shutdown_behavior)) | 81 if (!BeforeRunTask(shutdown_behavior)) |
80 return; | 82 return; |
81 | 83 |
82 // All tasks run through here and the scheduler itself doesn't use singletons. | 84 // All tasks run through here and the scheduler itself doesn't use singletons. |
83 // Therefore, it isn't necessary to reset the singleton allowed bit after | 85 // Therefore, it isn't necessary to reset the singleton allowed bit after |
84 // running the task. | 86 // running the task. |
85 ThreadRestrictions::SetSingletonAllowed( | 87 ThreadRestrictions::SetSingletonAllowed( |
86 task->traits.shutdown_behavior() != | 88 task->traits.shutdown_behavior() != |
87 TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN); | 89 TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN); |
88 | 90 |
89 debug::TaskAnnotator task_annotator; | 91 { |
90 task_annotator.RunTask(kQueueFunctionName, *task); | 92 // Set up TaskRunnerHandle as expected for the scope of the task. |
| 93 std::unique_ptr<SequencedTaskRunnerHandle> sequenced_task_runner_handle; |
| 94 std::unique_ptr<ThreadTaskRunnerHandle> single_thread_task_runner_handle; |
| 95 DCHECK(!task->sequenced_task_runner_ref || |
| 96 !task->single_thread_task_runner_ref); |
| 97 if (task->sequenced_task_runner_ref) { |
| 98 sequenced_task_runner_handle.reset( |
| 99 new SequencedTaskRunnerHandle(task->sequenced_task_runner_ref)); |
| 100 } else if (task->single_thread_task_runner_ref) { |
| 101 single_thread_task_runner_handle.reset( |
| 102 new ThreadTaskRunnerHandle(task->single_thread_task_runner_ref)); |
| 103 } |
| 104 |
| 105 debug::TaskAnnotator task_annotator; |
| 106 task_annotator.RunTask(kQueueFunctionName, *task); |
| 107 } |
91 | 108 |
92 AfterRunTask(shutdown_behavior); | 109 AfterRunTask(shutdown_behavior); |
93 } | 110 } |
94 | 111 |
95 bool TaskTracker::IsShuttingDownForTesting() const { | 112 bool TaskTracker::IsShuttingDownForTesting() const { |
96 AutoSchedulerLock auto_lock(lock_); | 113 AutoSchedulerLock auto_lock(lock_); |
97 return !!shutdown_cv_; | 114 return !!shutdown_cv_; |
98 } | 115 } |
99 | 116 |
100 bool TaskTracker::BeforePostTask(TaskShutdownBehavior shutdown_behavior) { | 117 bool TaskTracker::BeforePostTask(TaskShutdownBehavior shutdown_behavior) { |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 AutoSchedulerLock auto_lock(lock_); | 196 AutoSchedulerLock auto_lock(lock_); |
180 DCHECK_GT(num_tasks_blocking_shutdown_, 0U); | 197 DCHECK_GT(num_tasks_blocking_shutdown_, 0U); |
181 --num_tasks_blocking_shutdown_; | 198 --num_tasks_blocking_shutdown_; |
182 if (num_tasks_blocking_shutdown_ == 0 && shutdown_cv_) | 199 if (num_tasks_blocking_shutdown_ == 0 && shutdown_cv_) |
183 shutdown_cv_->Signal(); | 200 shutdown_cv_->Signal(); |
184 } | 201 } |
185 } | 202 } |
186 | 203 |
187 } // namespace internal | 204 } // namespace internal |
188 } // namespace base | 205 } // namespace base |
OLD | NEW |