Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(212)

Side by Side Diff: base/task_scheduler/task_tracker.cc

Issue 2076153002: [TaskScheduler] Support TaskRunnerHandles from parallel tasks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mix_c_Ab
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/task_scheduler/task_tracker.h ('k') | base/task_scheduler/task_tracker_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/threading/sequenced_task_runner_handle.h" 10 #include "base/threading/task_runner_handle.h"
11 #include "base/threading/thread_restrictions.h" 11 #include "base/threading/thread_restrictions.h"
12 #include "base/threading/thread_task_runner_handle.h"
13 #include "base/trace_event/trace_event.h" 12 #include "base/trace_event/trace_event.h"
14 13
15 namespace base { 14 namespace base {
16 namespace internal { 15 namespace internal {
17 16
18 namespace { 17 namespace {
19 18
20 const char kQueueFunctionName[] = "base::PostTask"; 19 const char kQueueFunctionName[] = "base::PostTask";
21 20
22 // This name conveys that a Task is run by the task scheduler without revealing 21 // This name conveys that a Task is run by the task scheduler without revealing
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 87
89 // All tasks run through here and the scheduler itself doesn't use singletons. 88 // All tasks run through here and the scheduler itself doesn't use singletons.
90 // Therefore, it isn't necessary to reset the singleton allowed bit after 89 // Therefore, it isn't necessary to reset the singleton allowed bit after
91 // running the task. 90 // running the task.
92 ThreadRestrictions::SetSingletonAllowed( 91 ThreadRestrictions::SetSingletonAllowed(
93 task->traits.shutdown_behavior() != 92 task->traits.shutdown_behavior() !=
94 TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN); 93 TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN);
95 94
96 { 95 {
97 // Set up TaskRunnerHandle as expected for the scope of the task. 96 // Set up TaskRunnerHandle as expected for the scope of the task.
98 std::unique_ptr<SequencedTaskRunnerHandle> sequenced_task_runner_handle; 97 std::unique_ptr<TaskRunnerHandle::TaskScope> task_scope;
99 std::unique_ptr<ThreadTaskRunnerHandle> single_thread_task_runner_handle; 98 std::unique_ptr<TaskRunnerHandle::SequencedTaskScope> sequenced_task_scope;
100 DCHECK(!task->sequenced_task_runner_ref || 99 std::unique_ptr<TaskRunnerHandle::SingleThreadTaskScope>
101 !task->single_thread_task_runner_ref); 100 single_thread_task_scope;
102 if (task->sequenced_task_runner_ref) { 101 if (task->task_runner_ref) {
103 sequenced_task_runner_handle.reset( 102 DCHECK(!task->sequenced_task_runner_ref &&
104 new SequencedTaskRunnerHandle(task->sequenced_task_runner_ref)); 103 !task->single_thread_task_runner_ref);
105 } else if (task->single_thread_task_runner_ref) { 104 task_scope.reset(new TaskRunnerHandle::TaskScope(task->task_runner_ref));
106 single_thread_task_runner_handle.reset( 105 } else if (task->sequenced_task_runner_ref) {
107 new ThreadTaskRunnerHandle(task->single_thread_task_runner_ref)); 106 DCHECK(!task->single_thread_task_runner_ref);
107 sequenced_task_scope.reset(new TaskRunnerHandle::SequencedTaskScope(
108 task->sequenced_task_runner_ref));
109 } else {
110 DCHECK(task->single_thread_task_runner_ref);
111 single_thread_task_scope.reset(
112 new TaskRunnerHandle::SingleThreadTaskScope(
113 task->single_thread_task_runner_ref));
108 } 114 }
109 115
110 TRACE_TASK_EXECUTION(kRunFunctionName, *task); 116 TRACE_TASK_EXECUTION(kRunFunctionName, *task);
111 117
112 debug::TaskAnnotator task_annotator; 118 debug::TaskAnnotator task_annotator;
113 task_annotator.RunTask(kQueueFunctionName, *task); 119 task_annotator.RunTask(kQueueFunctionName, *task);
114 } 120 }
115 121
116 AfterRunTask(shutdown_behavior); 122 AfterRunTask(shutdown_behavior);
117 } 123 }
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 AutoSchedulerLock auto_lock(lock_); 209 AutoSchedulerLock auto_lock(lock_);
204 DCHECK_GT(num_tasks_blocking_shutdown_, 0U); 210 DCHECK_GT(num_tasks_blocking_shutdown_, 0U);
205 --num_tasks_blocking_shutdown_; 211 --num_tasks_blocking_shutdown_;
206 if (num_tasks_blocking_shutdown_ == 0 && shutdown_cv_) 212 if (num_tasks_blocking_shutdown_ == 0 && shutdown_cv_)
207 shutdown_cv_->Signal(); 213 shutdown_cv_->Signal();
208 } 214 }
209 } 215 }
210 216
211 } // namespace internal 217 } // namespace internal
212 } // namespace base 218 } // namespace base
OLDNEW
« no previous file with comments | « base/task_scheduler/task_tracker.h ('k') | base/task_scheduler/task_tracker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698