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

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

Issue 2762703002: FOR REFERENCE ONLY Task Scheduler COM Task Runner (Closed)
Patch Set: Created 3 years, 9 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.cc ('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 <limits> 7 #include <limits>
8 #include <string> 8 #include <string>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 234
235 bool TaskTracker::RunTask(std::unique_ptr<Task> task, 235 bool TaskTracker::RunTask(std::unique_ptr<Task> task,
236 const SequenceToken& sequence_token) { 236 const SequenceToken& sequence_token) {
237 DCHECK(task); 237 DCHECK(task);
238 DCHECK(sequence_token.IsValid()); 238 DCHECK(sequence_token.IsValid());
239 239
240 const TaskShutdownBehavior shutdown_behavior = 240 const TaskShutdownBehavior shutdown_behavior =
241 task->traits.shutdown_behavior(); 241 task->traits.shutdown_behavior();
242 const bool can_run_task = BeforeRunTask(shutdown_behavior); 242 const bool can_run_task = BeforeRunTask(shutdown_behavior);
243 const bool is_delayed = !task->delayed_run_time.is_null(); 243 const bool is_delayed = !task->delayed_run_time.is_null();
244 const bool is_normal_task = task->task_type == Task::TaskType::NORMAL;
244 245
245 if (can_run_task) { 246 if (can_run_task) {
246 RecordTaskLatencyHistogram(task.get()); 247 if (is_normal_task)
248 RecordTaskLatencyHistogram(task.get());
247 249
248 const bool previous_singleton_allowed = 250 const bool previous_singleton_allowed =
249 ThreadRestrictions::SetSingletonAllowed( 251 ThreadRestrictions::SetSingletonAllowed(
250 task->traits.shutdown_behavior() != 252 task->traits.shutdown_behavior() !=
251 TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN); 253 TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN);
252 const bool previous_io_allowed = 254 const bool previous_io_allowed =
253 ThreadRestrictions::SetIOAllowed(task->traits.may_block()); 255 ThreadRestrictions::SetIOAllowed(task->traits.may_block());
254 const bool previous_wait_allowed = ThreadRestrictions::SetWaitAllowed( 256 const bool previous_wait_allowed = ThreadRestrictions::SetWaitAllowed(
255 task->traits.with_base_sync_primitives()); 257 task->traits.with_base_sync_primitives());
256 258
257 { 259 {
258 ScopedSetSequenceTokenForCurrentThread 260 ScopedSetSequenceTokenForCurrentThread
259 scoped_set_sequence_token_for_current_thread(sequence_token); 261 scoped_set_sequence_token_for_current_thread(sequence_token);
260 ScopedSetTaskPriorityForCurrentThread 262 ScopedSetTaskPriorityForCurrentThread
261 scoped_set_task_priority_for_current_thread(task->traits.priority()); 263 scoped_set_task_priority_for_current_thread(task->traits.priority());
262 264
263 // Set up TaskRunnerHandle as expected for the scope of the task. 265 // Set up TaskRunnerHandle as expected for the scope of the task.
264 std::unique_ptr<SequencedTaskRunnerHandle> sequenced_task_runner_handle; 266 std::unique_ptr<SequencedTaskRunnerHandle> sequenced_task_runner_handle;
265 std::unique_ptr<ThreadTaskRunnerHandle> single_thread_task_runner_handle; 267 std::unique_ptr<ThreadTaskRunnerHandle> single_thread_task_runner_handle;
266 DCHECK(!task->sequenced_task_runner_ref || 268 DCHECK(!task->sequenced_task_runner_ref ||
267 !task->single_thread_task_runner_ref); 269 !task->single_thread_task_runner_ref);
268 if (task->sequenced_task_runner_ref) { 270 if (task->sequenced_task_runner_ref) {
269 sequenced_task_runner_handle.reset( 271 sequenced_task_runner_handle.reset(
270 new SequencedTaskRunnerHandle(task->sequenced_task_runner_ref)); 272 new SequencedTaskRunnerHandle(task->sequenced_task_runner_ref));
271 } else if (task->single_thread_task_runner_ref) { 273 } else if (task->single_thread_task_runner_ref) {
272 single_thread_task_runner_handle.reset( 274 single_thread_task_runner_handle.reset(
273 new ThreadTaskRunnerHandle(task->single_thread_task_runner_ref)); 275 new ThreadTaskRunnerHandle(task->single_thread_task_runner_ref));
274 } 276 }
275 277
276 TRACE_TASK_EXECUTION(kRunFunctionName, *task); 278 if (is_normal_task) {
279 TRACE_TASK_EXECUTION(kRunFunctionName, *task);
277 280
278 const char* const execution_mode = 281 const char* const execution_mode =
279 task->single_thread_task_runner_ref 282 task->single_thread_task_runner_ref
280 ? kSingleThreadExecutionMode 283 ? kSingleThreadExecutionMode
281 : (task->sequenced_task_runner_ref ? kSequencedExecutionMode 284 : (task->sequenced_task_runner_ref ? kSequencedExecutionMode
282 : kParallelExecutionMode); 285 : kParallelExecutionMode);
283 // TODO(gab): In a better world this would be tacked on as an extra arg 286 // TODO(gab): In a better world this would be tacked on as an extra arg
284 // to the trace event generated above. This is not possible however until 287 // to the trace event generated above. This is not possible however
285 // http://crbug.com/652692 is resolved. 288 // until
286 TRACE_EVENT1("task_scheduler", "TaskTracker::RunTask", "task_info", 289 // http://crbug.com/652692 is resolved.
287 MakeUnique<TaskTracingInfo>(task->traits, execution_mode, 290 TRACE_EVENT1("task_scheduler", "TaskTracker::RunTask", "task_info",
288 sequence_token)); 291 MakeUnique<TaskTracingInfo>(task->traits, execution_mode,
292 sequence_token));
289 293
290 PerformRunTask(std::move(task)); 294 PerformRunTask(std::move(task));
295 } else {
296 // To avoid polluting Chrome traces with internal tasks, we simply just
297 // execute the task here.
298 std::move(task->task).Run();
299 }
291 } 300 }
292 301
293 ThreadRestrictions::SetWaitAllowed(previous_wait_allowed); 302 ThreadRestrictions::SetWaitAllowed(previous_wait_allowed);
294 ThreadRestrictions::SetIOAllowed(previous_io_allowed); 303 ThreadRestrictions::SetIOAllowed(previous_io_allowed);
295 ThreadRestrictions::SetSingletonAllowed(previous_singleton_allowed); 304 ThreadRestrictions::SetSingletonAllowed(previous_singleton_allowed);
296 305
297 AfterRunTask(shutdown_behavior); 306 AfterRunTask(shutdown_behavior);
298 } 307 }
299 308
300 if (!is_delayed) 309 if (!is_delayed && is_normal_task)
301 DecrementNumPendingUndelayedTasks(); 310 DecrementNumPendingUndelayedTasks();
302 311
303 return can_run_task; 312 return can_run_task;
304 } 313 }
305 314
306 bool TaskTracker::HasShutdownStarted() const { 315 bool TaskTracker::HasShutdownStarted() const {
307 return state_->HasShutdownStarted(); 316 return state_->HasShutdownStarted();
308 } 317 }
309 318
310 bool TaskTracker::IsShutdownComplete() const { 319 bool TaskTracker::IsShutdownComplete() const {
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 task_latency_histograms_[static_cast<int>(task->traits.priority())] 502 task_latency_histograms_[static_cast<int>(task->traits.priority())]
494 [task->traits.may_block() || 503 [task->traits.may_block() ||
495 task->traits.with_base_sync_primitives() 504 task->traits.with_base_sync_primitives()
496 ? 1 505 ? 1
497 : 0] 506 : 0]
498 ->AddTime(task_latency); 507 ->AddTime(task_latency);
499 } 508 }
500 509
501 } // namespace internal 510 } // namespace internal
502 } // namespace base 511 } // namespace base
OLDNEW
« no previous file with comments | « base/task_scheduler/task.cc ('k') | base/task_scheduler/task_tracker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698