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

Unified Diff: cc/raster/task_graph_work_queue.h

Issue 1521423003: Revert of 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cc/raster/task_graph_runner_perftest.cc ('k') | cc/raster/task_graph_work_queue.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/raster/task_graph_work_queue.h
diff --git a/cc/raster/task_graph_work_queue.h b/cc/raster/task_graph_work_queue.h
index 7b6840c55571a546141e617c7f90fb47984c949e..8a461232cbfbc536016a620317bef4e6f235ebb8 100644
--- a/cc/raster/task_graph_work_queue.h
+++ b/cc/raster/task_graph_work_queue.h
@@ -5,7 +5,6 @@
#ifndef CC_RASTER_TASK_GRAPH_WORK_QUEUE_H_
#define CC_RASTER_TASK_GRAPH_WORK_QUEUE_H_
-#include <algorithm>
#include <map>
#include <vector>
@@ -17,11 +16,6 @@
// Implements a queue of incoming TaskGraph work. Designed for use by
// implementations of TaskGraphRunner. Not thread safe, so the caller is
// responsible for all necessary locking.
-//
-// Tasks in the queue are divided into categories. Tasks from a single graph may
-// be put into different categories, each of which is prioritized independently
-// from the others. It is up to the implementation of TaskGraphRunner to
-// define the meaning of the categories and handle them appropriately.
class CC_EXPORT TaskGraphWorkQueue {
public:
struct TaskNamespace;
@@ -29,19 +23,12 @@
struct PrioritizedTask {
typedef std::vector<PrioritizedTask> Vector;
- PrioritizedTask(Task* task,
- TaskNamespace* task_namespace,
- uint16_t category,
- uint16_t priority)
- : task(task),
- task_namespace(task_namespace),
- category(category),
- priority(priority) {}
+ PrioritizedTask(Task* task, TaskNamespace* task_namespace, size_t priority)
+ : task(task), task_namespace(task_namespace), priority(priority) {}
Task* task;
TaskNamespace* task_namespace;
- uint16_t category;
- uint16_t priority;
+ size_t priority;
};
// Helper classes and static methods used by dependent classes.
@@ -54,9 +41,8 @@
// Current task graph.
TaskGraph graph;
- // Map from category to a vector of tasks that are ready to run for that
- // category.
- std::map<uint16_t, PrioritizedTask::Vector> ready_to_run_tasks;
+ // Ordered set of tasks that are ready to run.
+ PrioritizedTask::Vector ready_to_run_tasks;
// Completed tasks not yet collected by origin thread.
Task::Vector completed_tasks;
@@ -76,8 +62,8 @@
// previous tasks in the graph being replaced.
void ScheduleTasks(NamespaceToken token, TaskGraph* graph);
- // Returns the next task to run for the given category.
- PrioritizedTask GetNextTaskToRun(uint16_t category);
+ // Returns the next task to run paired with its namespace.
+ PrioritizedTask GetNextTaskToRun();
// Marks a task as completed, adding it to its namespace's list of completed
// tasks and updating the list of |ready_to_run_namespaces|.
@@ -98,35 +84,13 @@
return &it->second;
}
- static bool HasReadyToRunTasksInNamespace(
- const TaskNamespace* task_namespace) {
- return std::find_if(task_namespace->ready_to_run_tasks.begin(),
- task_namespace->ready_to_run_tasks.end(),
- [](const std::pair<uint16_t, PrioritizedTask::Vector>&
- ready_to_run_tasks) {
- return !ready_to_run_tasks.second.empty();
- }) != task_namespace->ready_to_run_tasks.end();
- }
-
static bool HasFinishedRunningTasksInNamespace(
const TaskNamespace* task_namespace) {
return task_namespace->running_tasks.empty() &&
- !HasReadyToRunTasksInNamespace(task_namespace);
+ task_namespace->ready_to_run_tasks.empty();
}
- bool HasReadyToRunTasks() const {
- return std::find_if(ready_to_run_namespaces_.begin(),
- ready_to_run_namespaces_.end(),
- [](const std::pair<uint16_t, TaskNamespace::Vector>&
- ready_to_run_namespaces) {
- return !ready_to_run_namespaces.second.empty();
- }) != ready_to_run_namespaces_.end();
- }
-
- bool HasReadyToRunTasksForCategory(uint16_t category) const {
- auto found = ready_to_run_namespaces_.find(category);
- return found != ready_to_run_namespaces_.end() && !found->second.empty();
- }
+ bool HasReadyToRunTasks() const { return !ready_to_run_namespaces_.empty(); }
bool HasAnyNamespaces() const { return !namespaces_.empty(); }
@@ -136,11 +100,6 @@
[](const TaskNamespaceMap::value_type& entry) {
return !HasFinishedRunningTasksInNamespace(&entry.second);
}) == namespaces_.end();
- }
-
- const std::map<uint16_t, TaskNamespace::Vector>& ready_to_run_namespaces()
- const {
- return ready_to_run_namespaces_;
}
// Helper function which ensures that graph dependencies were correctly
@@ -157,13 +116,29 @@
}
};
+ static bool CompareTaskPriority(const PrioritizedTask& a,
+ const PrioritizedTask& b) {
+ // In this system, numerically lower priority is run first.
+ return a.priority > b.priority;
+ }
+
+ static bool CompareTaskNamespacePriority(const TaskNamespace* a,
+ const TaskNamespace* b) {
+ DCHECK(!a->ready_to_run_tasks.empty());
+ DCHECK(!b->ready_to_run_tasks.empty());
+
+ // Compare based on task priority of the ready_to_run_tasks heap .front()
+ // will hold the max element of the heap, except after pop_heap, when max
+ // element is moved to .back().
+ return CompareTaskPriority(a->ready_to_run_tasks.front(),
+ b->ready_to_run_tasks.front());
+ }
+
using TaskNamespaceMap =
std::map<NamespaceToken, TaskNamespace, CompareToken>;
TaskNamespaceMap namespaces_;
-
- // Map from category to a vector of ready to run namespaces for that category.
- std::map<uint16_t, TaskNamespace::Vector> ready_to_run_namespaces_;
+ TaskNamespace::Vector ready_to_run_namespaces_;
// Provides a unique id to each NamespaceToken.
int next_namespace_id_;
« no previous file with comments | « cc/raster/task_graph_runner_perftest.cc ('k') | cc/raster/task_graph_work_queue.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698