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 | 12 |
11 namespace base { | 13 namespace base { |
12 namespace internal { | 14 namespace internal { |
13 | 15 |
14 namespace { | 16 namespace { |
15 | 17 |
16 const char kQueueFunctionName[] = "base::PostTask"; | 18 const char kQueueFunctionName[] = "base::PostTask"; |
17 | 19 |
18 // Upper bound for the | 20 // Upper bound for the |
19 // TaskScheduler.BlockShutdownTasksPostedDuringShutdown histogram. | 21 // TaskScheduler.BlockShutdownTasksPostedDuringShutdown histogram. |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
71 } | 73 } |
72 | 74 |
73 void TaskTracker::RunTask(const Task* task) { | 75 void TaskTracker::RunTask(const Task* task) { |
74 DCHECK(task); | 76 DCHECK(task); |
75 | 77 |
76 const TaskShutdownBehavior shutdown_behavior = | 78 const TaskShutdownBehavior shutdown_behavior = |
77 task->traits.shutdown_behavior(); | 79 task->traits.shutdown_behavior(); |
78 if (!BeforeRunTask(shutdown_behavior)) | 80 if (!BeforeRunTask(shutdown_behavior)) |
79 return; | 81 return; |
80 | 82 |
81 debug::TaskAnnotator task_annotator; | 83 { |
82 task_annotator.RunTask(kQueueFunctionName, *task); | 84 // Set up TaskRunnerHandle as expected for the scope of the task. |
85 std::unique_ptr<SequencedTaskRunnerHandle> sequenced_trh; | |
86 std::unique_ptr<ThreadTaskRunnerHandle> single_thread_trh; | |
87 DCHECK(!task->sequenced_task_runner_ref || | |
robliao
2016/04/28 17:16:42
Alternatively, you can have an else clause below w
gab
2016/04/28 17:55:07
An else clause below would be a
DCHECK(task->sequ
robliao
2016/04/28 18:06:47
Ah yes, my misreading. I think Chrome tends to pre
gab
2016/04/28 18:50:15
I prefer the current one as it reads more as "the
| |
88 !task->single_thread_task_runner_ref); | |
89 if (task->sequenced_task_runner_ref) { | |
90 sequenced_trh.reset( | |
91 new SequencedTaskRunnerHandle(task->sequenced_task_runner_ref)); | |
92 } else if (task->single_thread_task_runner_ref) { | |
93 single_thread_trh.reset( | |
94 new ThreadTaskRunnerHandle(task->single_thread_task_runner_ref)); | |
95 } | |
96 | |
97 debug::TaskAnnotator task_annotator; | |
98 task_annotator.RunTask(kQueueFunctionName, *task); | |
99 } | |
83 | 100 |
84 AfterRunTask(shutdown_behavior); | 101 AfterRunTask(shutdown_behavior); |
85 } | 102 } |
86 | 103 |
87 bool TaskTracker::IsShuttingDownForTesting() const { | 104 bool TaskTracker::IsShuttingDownForTesting() const { |
88 AutoSchedulerLock auto_lock(lock_); | 105 AutoSchedulerLock auto_lock(lock_); |
89 return !!shutdown_cv_; | 106 return !!shutdown_cv_; |
90 } | 107 } |
91 | 108 |
92 bool TaskTracker::BeforePostTask(TaskShutdownBehavior shutdown_behavior) { | 109 bool TaskTracker::BeforePostTask(TaskShutdownBehavior shutdown_behavior) { |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
171 AutoSchedulerLock auto_lock(lock_); | 188 AutoSchedulerLock auto_lock(lock_); |
172 DCHECK_GT(num_tasks_blocking_shutdown_, 0U); | 189 DCHECK_GT(num_tasks_blocking_shutdown_, 0U); |
173 --num_tasks_blocking_shutdown_; | 190 --num_tasks_blocking_shutdown_; |
174 if (num_tasks_blocking_shutdown_ == 0 && shutdown_cv_) | 191 if (num_tasks_blocking_shutdown_ == 0 && shutdown_cv_) |
175 shutdown_cv_->Signal(); | 192 shutdown_cv_->Signal(); |
176 } | 193 } |
177 } | 194 } |
178 | 195 |
179 } // namespace internal | 196 } // namespace internal |
180 } // namespace base | 197 } // namespace base |
OLD | NEW |