Index: cc/resources/task_graph_runner.h |
diff --git a/cc/resources/task_graph_runner.h b/cc/resources/task_graph_runner.h |
index 2ff085d76cb9fd5eac10414d2a7d6768c85acd86..204c169da494b6cc78c36824fda54d3c4c3ccef7 100644 |
--- a/cc/resources/task_graph_runner.h |
+++ b/cc/resources/task_graph_runner.h |
@@ -5,6 +5,7 @@ |
#ifndef CC_RESOURCES_TASK_GRAPH_RUNNER_H_ |
#define CC_RESOURCES_TASK_GRAPH_RUNNER_H_ |
+#include <array> |
#include <map> |
#include <vector> |
@@ -53,12 +54,22 @@ struct CC_EXPORT TaskGraph { |
typedef std::vector<Node> Vector; |
- Node(Task* task, unsigned priority, size_t dependencies) |
- : task(task), priority(priority), dependencies(dependencies) {} |
+ Node(Task* task, |
+ unsigned priority, |
danakj
2015/02/23 18:45:01
did git cl format do this? it seems to have disabl
|
+ size_t dependencies, |
+ int sub_namespace, |
+ int max_concurrent_tasks) |
+ : task(task), |
+ priority(priority), |
+ dependencies(dependencies), |
+ sub_namespace(sub_namespace), |
+ max_concurrent_tasks(max_concurrent_tasks) {} |
Task* task; |
unsigned priority; |
size_t dependencies; |
+ int sub_namespace; |
+ int max_concurrent_tasks; |
}; |
struct Edge { |
@@ -141,26 +152,54 @@ class CC_EXPORT TaskGraphRunner { |
struct PrioritizedTask { |
typedef std::vector<PrioritizedTask> Vector; |
- PrioritizedTask(Task* task, unsigned priority) |
- : task(task), priority(priority) {} |
+ PrioritizedTask(Task* task, unsigned priority, int max_concurrent_tasks) |
+ : task(task), |
+ priority(priority), |
+ max_concurrent_tasks(max_concurrent_tasks) {} |
Task* task; |
unsigned priority; |
+ int max_concurrent_tasks; |
}; |
typedef std::vector<const Task*> TaskVector; |
+ struct TaskNamespace; |
+ |
+ struct TaskSubNamespace { |
+ typedef std::vector<TaskSubNamespace*> Vector; |
danakj
2015/02/23 18:45:01
prefer using instead of typedef
|
+ |
+ TaskSubNamespace(); |
+ ~TaskSubNamespace(); |
+ bool IsReadyToRun() const; |
+ |
+ // Task namespace this belongs to. |
+ TaskNamespace* task_namespace; |
+ |
+ bool is_in_ready_sub_namespaces; |
+ |
+ // Number of currently running tasks in this sub namespace. |
+ int running_task_count; |
+ |
+ // Ordered set of tasks that are ready to run. |
+ PrioritizedTask::Vector ready_to_run_tasks; |
+ }; |
+ |
struct TaskNamespace { |
typedef std::vector<TaskNamespace*> Vector; |
+ static const int kNumberOfSubNamespaces = 2; |
danakj
2015/02/23 18:45:01
this 2 looks pretty magical here, is it possible t
|
+ static const int kDefaultSubNamespace = 0; |
danakj
2015/02/23 18:45:01
There's at least 2 constants with this name in thi
|
+ |
TaskNamespace(); |
~TaskNamespace(); |
// Current task graph. |
TaskGraph graph; |
- // Ordered set of tasks that are ready to run. |
- PrioritizedTask::Vector ready_to_run_tasks; |
+ typedef std::array<TaskSubNamespace, kNumberOfSubNamespaces> |
danakj
2015/02/23 18:45:01
std::array is c++11 library feature no? (ie can't
danakj
2015/02/23 18:45:01
using
|
+ SubNamespaceArray; |
+ SubNamespaceArray sub_namespaces; |
// Completed tasks not yet collected by origin thread. |
Task::Vector completed_tasks; |
@@ -177,8 +216,8 @@ class CC_EXPORT TaskGraphRunner { |
return a.priority > b.priority; |
} |
- static bool CompareTaskNamespacePriority(const TaskNamespace* a, |
- const TaskNamespace* b) { |
+ static bool CompareTaskSubNamespacePriority(const TaskSubNamespace* a, |
+ const TaskSubNamespace* b) { |
DCHECK(!a->ready_to_run_tasks.empty()); |
DCHECK(!b->ready_to_run_tasks.empty()); |
@@ -191,8 +230,14 @@ class CC_EXPORT TaskGraphRunner { |
static bool HasFinishedRunningTasksInNamespace( |
const TaskNamespace* task_namespace) { |
- return task_namespace->running_tasks.empty() && |
- task_namespace->ready_to_run_tasks.empty(); |
+ if (!task_namespace->running_tasks.empty()) |
+ return false; |
+ for (const TaskSubNamespace& sub_namespace : |
+ task_namespace->sub_namespaces) { |
+ if (!sub_namespace.ready_to_run_tasks.empty()) |
+ return false; |
+ } |
+ return true; |
} |
// Run next task. Caller must acquire |lock_| prior to calling this function |
@@ -218,8 +263,8 @@ class CC_EXPORT TaskGraphRunner { |
// not yet collected. |
TaskNamespaceMap namespaces_; |
- // Ordered set of task namespaces that have ready to run tasks. |
- TaskNamespace::Vector ready_to_run_namespaces_; |
+ // Ordered set of task sub namespaces that have ready to run tasks. |
+ TaskSubNamespace::Vector ready_to_run_sub_namespaces_; |
// Set during shutdown. Tells Run() to return when no more tasks are pending. |
bool shutdown_; |