| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/resources/task_graph_runner.h" | 5 #include "cc/resources/task_graph_runner.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/containers/hash_tables.h" | 9 #include "base/containers/hash_tables.h" |
| 10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| 11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 12 #include "base/threading/thread_restrictions.h" | 12 #include "base/threading/thread_restrictions.h" |
| 13 | 13 |
| 14 namespace cc { | 14 namespace cc { |
| 15 namespace internal { | 15 namespace internal { |
| 16 | 16 |
| 17 Task::Task() : did_schedule_(false), did_run_(false) {} | 17 Task::Task() : did_run_(false) {} |
| 18 | 18 |
| 19 Task::~Task() { DCHECK(!did_run_ || did_schedule_); } | 19 Task::~Task() {} |
| 20 | |
| 21 void Task::DidSchedule() { did_schedule_ = true; } | |
| 22 | 20 |
| 23 void Task::WillRun() { | 21 void Task::WillRun() { |
| 24 DCHECK(did_schedule_); | |
| 25 DCHECK(!did_run_); | 22 DCHECK(!did_run_); |
| 26 } | 23 } |
| 27 | 24 |
| 28 void Task::DidRun() { did_run_ = true; } | 25 void Task::DidRun() { did_run_ = true; } |
| 29 | 26 |
| 30 bool Task::HasFinishedRunning() const { return did_run_; } | 27 bool Task::HasFinishedRunning() const { return did_run_; } |
| 31 | 28 |
| 32 GraphNode::GraphNode(Task* task, unsigned priority) | 29 GraphNode::GraphNode(Task* task, unsigned priority) |
| 33 : task_(task), priority_(priority), num_dependencies_(0) {} | 30 : task_(task), priority_(priority), num_dependencies_(0) {} |
| 34 | 31 |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 for (TaskGraph::iterator it = new_pending_tasks.begin(); | 164 for (TaskGraph::iterator it = new_pending_tasks.begin(); |
| 168 it != new_pending_tasks.end(); | 165 it != new_pending_tasks.end(); |
| 169 ++it) { | 166 ++it) { |
| 170 Task* task = it->first; | 167 Task* task = it->first; |
| 171 DCHECK(task); | 168 DCHECK(task); |
| 172 GraphNode* node = it->second; | 169 GraphNode* node = it->second; |
| 173 | 170 |
| 174 // Completed tasks should not exist in |new_pending_tasks|. | 171 // Completed tasks should not exist in |new_pending_tasks|. |
| 175 DCHECK(!task->HasFinishedRunning()); | 172 DCHECK(!task->HasFinishedRunning()); |
| 176 | 173 |
| 177 // Call DidSchedule() to indicate that this task has been scheduled. | |
| 178 // Note: This is only for debugging purposes. | |
| 179 task->DidSchedule(); | |
| 180 | |
| 181 if (!node->num_dependencies()) | 174 if (!node->num_dependencies()) |
| 182 task_namespace->ready_to_run_tasks.push_back(node); | 175 task_namespace->ready_to_run_tasks.push_back(node); |
| 183 | 176 |
| 184 // Erase the task from old pending tasks. | 177 // Erase the task from old pending tasks. |
| 185 task_namespace->pending_tasks.erase(task); | 178 task_namespace->pending_tasks.erase(task); |
| 186 } | 179 } |
| 187 | 180 |
| 188 // Rearrange the elements in |ready_to_run_tasks| in such a way that | 181 // Rearrange the elements in |ready_to_run_tasks| in such a way that |
| 189 // they form a heap. | 182 // they form a heap. |
| 190 std::make_heap(task_namespace->ready_to_run_tasks.begin(), | 183 std::make_heap(task_namespace->ready_to_run_tasks.begin(), |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 // Finally add task to |completed_tasks_|. | 388 // Finally add task to |completed_tasks_|. |
| 396 task_namespace->completed_tasks.push_back(task); | 389 task_namespace->completed_tasks.push_back(task); |
| 397 | 390 |
| 398 // If namespace has finished running all tasks, wake up origin thread. | 391 // If namespace has finished running all tasks, wake up origin thread. |
| 399 if (HasFinishedRunningTasksInNamespace(task_namespace)) | 392 if (HasFinishedRunningTasksInNamespace(task_namespace)) |
| 400 has_namespaces_with_finished_running_tasks_cv_.Signal(); | 393 has_namespaces_with_finished_running_tasks_cv_.Signal(); |
| 401 } | 394 } |
| 402 | 395 |
| 403 } // namespace internal | 396 } // namespace internal |
| 404 } // namespace cc | 397 } // namespace cc |
| OLD | NEW |