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

Side by Side Diff: cc/raster/synchronous_task_graph_runner.cc

Issue 1489233003: TaskGraphRunner Group support (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@refactor
Patch Set: Created 5 years 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 | « cc/raster/synchronous_task_graph_runner.h ('k') | cc/raster/task_graph_runner.h » ('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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "cc/raster/synchronous_task_graph_runner.h" 5 #include "cc/raster/synchronous_task_graph_runner.h"
6 6
7 #include <algorithm>
8 #include <utility>
9
7 #include "base/threading/simple_thread.h" 10 #include "base/threading/simple_thread.h"
8 #include "base/threading/thread_restrictions.h" 11 #include "base/threading/thread_restrictions.h"
9 #include "base/trace_event/trace_event.h" 12 #include "base/trace_event/trace_event.h"
10 13
11 namespace cc { 14 namespace cc {
12 15
13 SynchronousTaskGraphRunner::SynchronousTaskGraphRunner() {} 16 SynchronousTaskGraphRunner::SynchronousTaskGraphRunner() {}
14 17
15 SynchronousTaskGraphRunner::~SynchronousTaskGraphRunner() { 18 SynchronousTaskGraphRunner::~SynchronousTaskGraphRunner() {
16 DCHECK(!work_queue_.HasReadyToRunTasks()); 19 DCHECK(!work_queue_.HasReadyToRunTasks());
(...skipping 17 matching lines...) Expand all
34 void SynchronousTaskGraphRunner::WaitForTasksToFinishRunning( 37 void SynchronousTaskGraphRunner::WaitForTasksToFinishRunning(
35 NamespaceToken token) { 38 NamespaceToken token) {
36 TRACE_EVENT0("cc", "SynchronousTaskGraphRunner::WaitForTasksToFinishRunning"); 39 TRACE_EVENT0("cc", "SynchronousTaskGraphRunner::WaitForTasksToFinishRunning");
37 40
38 DCHECK(token.IsValid()); 41 DCHECK(token.IsValid());
39 auto* task_namespace = work_queue_.GetNamespaceForToken(token); 42 auto* task_namespace = work_queue_.GetNamespaceForToken(token);
40 43
41 if (!task_namespace) 44 if (!task_namespace)
42 return; 45 return;
43 46
44 while ( 47 while (!work_queue_.HasFinishedRunningTasksInNamespace(task_namespace)) {
45 !TaskGraphWorkQueue::HasFinishedRunningTasksInNamespace(task_namespace)) { 48 bool succeeded = RunTask();
46 RunTask(); 49 DCHECK(succeeded);
47 } 50 }
48 } 51 }
49 52
50 void SynchronousTaskGraphRunner::CollectCompletedTasks( 53 void SynchronousTaskGraphRunner::CollectCompletedTasks(
51 NamespaceToken token, 54 NamespaceToken token,
52 Task::Vector* completed_tasks) { 55 Task::Vector* completed_tasks) {
53 TRACE_EVENT0("cc", "SynchronousTaskGraphRunner::CollectCompletedTasks"); 56 TRACE_EVENT0("cc", "SynchronousTaskGraphRunner::CollectCompletedTasks");
54 57
55 DCHECK(token.IsValid()); 58 DCHECK(token.IsValid());
56 work_queue_.CollectCompletedTasks(token, completed_tasks); 59 work_queue_.CollectCompletedTasks(token, completed_tasks);
57 } 60 }
58 61
59 void SynchronousTaskGraphRunner::RunUntilIdle() { 62 void SynchronousTaskGraphRunner::RunUntilIdle() {
60 while (work_queue_.HasReadyToRunTasks()) 63 while (RunTask()) {
61 RunTask(); 64 }
62 } 65 }
63 66
64 void SynchronousTaskGraphRunner::RunTask() { 67 bool SynchronousTaskGraphRunner::RunTask() {
65 TRACE_EVENT0("toplevel", "SynchronousTaskGraphRunner::RunTask"); 68 TRACE_EVENT0("toplevel", "SynchronousTaskGraphRunner::RunTask");
66 69
67 auto prioritized_task = work_queue_.GetNextTaskToRun(); 70 // Find the first category with any tasks to run. This task graph runner
71 // treats categories as an additional priority.
72 const auto& ready_to_run_namespaces = work_queue_.ready_to_run_namespaces();
73 auto found = std::find_if(
74 ready_to_run_namespaces.cbegin(), ready_to_run_namespaces.cend(),
75 [](const std::pair<uint16_t, TaskGraphWorkQueue::TaskNamespace::Vector>&
76 pair) { return !pair.second.empty(); });
77
78 if (found == ready_to_run_namespaces.cend()) {
79 return false;
80 }
81
82 const uint16_t category = found->first;
83 auto prioritized_task = work_queue_.GetNextTaskToRun(category);
68 84
69 Task* task = prioritized_task.task; 85 Task* task = prioritized_task.task;
70 task->WillRun(); 86 task->WillRun();
71 task->RunOnWorkerThread(); 87 task->RunOnWorkerThread();
72 task->DidRun(); 88 task->DidRun();
73 89
74 work_queue_.CompleteTask(prioritized_task); 90 work_queue_.CompleteTask(prioritized_task);
91
92 return true;
75 } 93 }
76 94
77 } // namespace cc 95 } // namespace cc
OLDNEW
« no previous file with comments | « cc/raster/synchronous_task_graph_runner.h ('k') | cc/raster/task_graph_runner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698