Chromium Code Reviews| Index: cc/resources/worker_pool.cc |
| diff --git a/cc/resources/worker_pool.cc b/cc/resources/worker_pool.cc |
| old mode 100644 |
| new mode 100755 |
| index dca0c704f09dbc2559bf3f4adf860724ce9a6240..c1356758ba4eb1a1f7b66abe40eced0374b3908c |
| --- a/cc/resources/worker_pool.cc |
| +++ b/cc/resources/worker_pool.cc |
| @@ -8,100 +8,53 @@ |
| #include <queue> |
| #include "base/bind.h" |
| +#include "base/command_line.h" |
|
reveman
2013/12/28 14:45:48
please remove this include if not needed.
sohanjg
2013/12/30 06:49:36
Done.
|
| #include "base/containers/hash_tables.h" |
| #include "base/debug/trace_event.h" |
| +#include "base/lazy_instance.h" |
| +#include "base/memory/linked_ptr.h" |
| #include "base/strings/stringprintf.h" |
| #include "base/synchronization/condition_variable.h" |
| #include "base/threading/simple_thread.h" |
| #include "base/threading/thread_restrictions.h" |
| #include "cc/base/scoped_ptr_deque.h" |
| +#include "cc/base/switches.h" |
| namespace cc { |
| -namespace internal { |
| - |
| -WorkerPoolTask::WorkerPoolTask() |
| - : did_schedule_(false), |
| - did_run_(false), |
| - did_complete_(false) { |
| -} |
| - |
| -WorkerPoolTask::~WorkerPoolTask() { |
| - DCHECK_EQ(did_schedule_, did_complete_); |
| - DCHECK(!did_run_ || did_schedule_); |
| - DCHECK(!did_run_ || did_complete_); |
| -} |
| - |
| -void WorkerPoolTask::DidSchedule() { |
| - DCHECK(!did_complete_); |
| - did_schedule_ = true; |
| -} |
| - |
| -void WorkerPoolTask::WillRun() { |
| - DCHECK(did_schedule_); |
| - DCHECK(!did_complete_); |
| - DCHECK(!did_run_); |
| -} |
| - |
| -void WorkerPoolTask::DidRun() { |
| - did_run_ = true; |
| -} |
| - |
| -void WorkerPoolTask::WillComplete() { |
| - DCHECK(!did_complete_); |
| -} |
| - |
| -void WorkerPoolTask::DidComplete() { |
| - DCHECK(did_schedule_); |
| - DCHECK(!did_complete_); |
| - did_complete_ = true; |
| -} |
| +namespace { |
| -bool WorkerPoolTask::HasFinishedRunning() const { |
| - return did_run_; |
| -} |
| - |
| -bool WorkerPoolTask::HasCompleted() const { |
| - return did_complete_; |
| -} |
| - |
| -GraphNode::GraphNode(internal::WorkerPoolTask* task, unsigned priority) |
| - : task_(task), |
| - priority_(priority), |
| - num_dependencies_(0) { |
| -} |
| - |
| -GraphNode::~GraphNode() { |
| -} |
| - |
| -} // namespace internal |
| - |
| -// Internal to the worker pool. Any data or logic that needs to be |
| -// shared between threads lives in this class. All members are guarded |
| -// by |lock_|. |
| -class WorkerPool::Inner : public base::DelegateSimpleThread::Delegate { |
| +// TaskGraphRunners can process task graphs from multiple |
| +// workerpool instances. All members are guarded by |lock_|. |
| +class TaskGraphRunner : public base::DelegateSimpleThread::Delegate { |
| public: |
| - Inner(size_t num_threads, const std::string& thread_name_prefix); |
| - virtual ~Inner(); |
| + typedef WorkerPool::TaskGraph TaskGraph; |
| + typedef WorkerPool::TaskVector TaskVector; |
| + |
| + TaskGraphRunner(size_t num_threads, const std::string& thread_name_prefix); |
| + virtual ~TaskGraphRunner(); |
| - void Shutdown(); |
| + void Register(const WorkerPool* worker_pool); |
| + void Unregister(const WorkerPool* worker_pool); |
| + void WaitForTasksToFinishRunning(const WorkerPool* worker_pool); |
| // Schedule running of tasks in |graph|. Tasks previously scheduled but |
| // no longer needed will be canceled unless already running. Canceled |
| - // tasks are moved to |completed_tasks_| without being run. The result |
| + // tasks are moved to |completed_tasks| without being run. The result |
| // is that once scheduled, a task is guaranteed to end up in the |
| - // |completed_tasks_| queue even if they later get canceled by another |
| + // |completed_tasks| queue even if it later get canceled by another |
| // call to SetTaskGraph(). |
| - void SetTaskGraph(TaskGraph* graph); |
| + void SetTaskGraph(const WorkerPool* worker_pool, TaskGraph* graph); |
| // Collect all completed tasks in |completed_tasks|. |
| - void CollectCompletedTasks(TaskVector* completed_tasks); |
| + void CollectCompletedTasks(const WorkerPool* worker_pool, |
| + TaskVector* completed_tasks); |
| private: |
| - class PriorityComparator { |
| + class TaskPriorityComparator { |
| public: |
| - bool operator()(const internal::GraphNode* a, |
| - const internal::GraphNode* b) { |
| + bool operator()(internal::GraphNode* a, |
| + internal::GraphNode* b) { |
| // In this system, numerically lower priority is run first. |
| if (a->priority() != b->priority()) |
| return a->priority() > b->priority(); |
| @@ -111,9 +64,45 @@ class WorkerPool::Inner : public base::DelegateSimpleThread::Delegate { |
| } |
| }; |
| + // Ordered set of tasks that are ready to run. |
| + typedef std::priority_queue<internal::GraphNode*, |
| + std::vector<internal::GraphNode*>, |
| + TaskPriorityComparator> TaskQueue; |
| + |
| + struct TaskNamespace { |
| + TaskGraph pending_tasks; |
| + TaskGraph running_tasks; |
| + TaskVector completed_tasks; |
| + TaskQueue ready_to_run_tasks; |
| + }; |
| + |
| + class TaskNamespacePriorityComparator { |
| + public: |
| + bool operator()(TaskNamespace* a, |
| + TaskNamespace* b) { |
| + return task_comparators_.operator()(a->ready_to_run_tasks.top(), |
| + b->ready_to_run_tasks.top()); |
| + } |
| + TaskPriorityComparator task_comparators_; |
| + }; |
| + |
| + typedef std::map<const WorkerPool*, linked_ptr<TaskNamespace> > |
| + TaskNamespaceMap; |
| + |
| + // Ordered set of tasks namespaces that have ready to run tasks. |
| + typedef std::priority_queue<TaskNamespace*, |
| + std::vector<TaskNamespace*>, |
| + TaskNamespacePriorityComparator> |
| + TaskNamespaceQueue; |
| + |
| // Overridden from base::DelegateSimpleThread: |
| virtual void Run() OVERRIDE; |
| + inline bool has_finished_running_tasks(TaskNamespace* task_namespace) { |
| + return (task_namespace->pending_tasks.empty() && |
| + task_namespace->running_tasks.empty()); |
| + } |
| + |
| // This lock protects all members of this class except |
| // |worker_pool_on_origin_thread_|. Do not read or modify anything |
| // without holding this lock. Do not block while holding this lock. |
| @@ -123,6 +112,10 @@ class WorkerPool::Inner : public base::DelegateSimpleThread::Delegate { |
| // tasks are ready to run or shutdown starts. |
| base::ConditionVariable has_ready_to_run_tasks_cv_; |
| + // Condition variable that is waited on by origin threads until a |
| + // namespace has finished running all associated tasks. |
| + base::ConditionVariable has_namespaces_with_finished_running_tasks_cv_; |
| + |
| // Provides each running thread loop with a unique index. First thread |
| // loop index is 0. |
| unsigned next_thread_index_; |
| @@ -131,30 +124,20 @@ class WorkerPool::Inner : public base::DelegateSimpleThread::Delegate { |
| // are pending. |
| bool shutdown_; |
| - // This set contains all pending tasks. |
| - GraphNodeMap pending_tasks_; |
| - |
| - // Ordered set of tasks that are ready to run. |
| - typedef std::priority_queue<internal::GraphNode*, |
| - std::vector<internal::GraphNode*>, |
| - PriorityComparator> TaskQueue; |
| - TaskQueue ready_to_run_tasks_; |
| - |
| - // This set contains all currently running tasks. |
| - GraphNodeMap running_tasks_; |
| + ScopedPtrDeque<base::DelegateSimpleThread> workers_; |
| - // Completed tasks not yet collected by origin thread. |
| - TaskVector completed_tasks_; |
| + TaskNamespaceMap namespaces_; |
| - ScopedPtrDeque<base::DelegateSimpleThread> workers_; |
| + TaskNamespaceQueue ready_to_run_namespaces_; |
| - DISALLOW_COPY_AND_ASSIGN(Inner); |
| + DISALLOW_COPY_AND_ASSIGN(TaskGraphRunner); |
| }; |
| -WorkerPool::Inner::Inner( |
| +TaskGraphRunner::TaskGraphRunner( |
| size_t num_threads, const std::string& thread_name_prefix) |
| : lock_(), |
| has_ready_to_run_tasks_cv_(&lock_), |
| + has_namespaces_with_finished_running_tasks_cv_(&lock_), |
| next_thread_index_(0), |
| shutdown_(false) { |
| base::AutoLock lock(lock_); |
| @@ -175,21 +158,13 @@ WorkerPool::Inner::Inner( |
| } |
| } |
| -WorkerPool::Inner::~Inner() { |
| - base::AutoLock lock(lock_); |
| - |
| - DCHECK(shutdown_); |
| - |
| - DCHECK_EQ(0u, pending_tasks_.size()); |
| - DCHECK_EQ(0u, ready_to_run_tasks_.size()); |
| - DCHECK_EQ(0u, running_tasks_.size()); |
| - DCHECK_EQ(0u, completed_tasks_.size()); |
| -} |
| - |
| -void WorkerPool::Inner::Shutdown() { |
| +TaskGraphRunner::~TaskGraphRunner() { |
| { |
| base::AutoLock lock(lock_); |
| + DCHECK_EQ(0u, ready_to_run_namespaces_.size()); |
| + DCHECK_EQ(0u, namespaces_.size()); |
| + |
| DCHECK(!shutdown_); |
| shutdown_ = true; |
| @@ -207,23 +182,68 @@ void WorkerPool::Inner::Shutdown() { |
| } |
| } |
| -void WorkerPool::Inner::SetTaskGraph(TaskGraph* graph) { |
| +void TaskGraphRunner::Register(const WorkerPool* worker_pool) { |
| + base::AutoLock lock(lock_); |
| + |
| + DCHECK(namespaces_.find(worker_pool) == namespaces_.end()); |
| + linked_ptr<TaskNamespace> task_set = make_linked_ptr(new TaskNamespace()); |
| + namespaces_[worker_pool] = task_set; |
| +} |
| + |
| +void TaskGraphRunner::Unregister(const WorkerPool* worker_pool) { |
| + base::AutoLock lock(lock_); |
| + |
| + DCHECK(namespaces_.find(worker_pool) != namespaces_.end()); |
| + |
| + TaskNamespace* task_namespace = namespaces_[worker_pool].get(); |
| + DCHECK_EQ(0u, task_namespace->pending_tasks.size()); |
| + DCHECK_EQ(0u, task_namespace->ready_to_run_tasks.size()); |
| + DCHECK_EQ(0u, task_namespace->running_tasks.size()); |
| + DCHECK_EQ(0u, task_namespace->completed_tasks.size()); |
| + |
| + namespaces_.erase(worker_pool); |
| +} |
| + |
| +void TaskGraphRunner::WaitForTasksToFinishRunning( |
| + const WorkerPool* worker_pool) { |
| + base::AutoLock lock(lock_); |
| + |
| + DCHECK(namespaces_.find(worker_pool) != namespaces_.end()); |
| + TaskNamespace* task_namespace = namespaces_[worker_pool].get(); |
| + |
| + while (true) { |
| + if (has_finished_running_tasks(task_namespace)) { |
| + // There maybe other namespaces that have finished running |
|
reveman
2013/12/28 14:45:48
nit: s/maybe/may be/
sohanjg
2013/12/30 06:49:36
Done.
|
| + // running tasks, so wake up another origin thread |
|
reveman
2013/12/28 14:45:48
nit: "running" twice. remove "running" from this l
sohanjg
2013/12/30 06:49:36
Done.
|
| + has_namespaces_with_finished_running_tasks_cv_.Signal(); |
| + return; |
| + } |
| + has_namespaces_with_finished_running_tasks_cv_.Wait(); |
| + } |
| +} |
| + |
| +void TaskGraphRunner::SetTaskGraph(const WorkerPool* worker_pool, |
| + TaskGraph* graph) { |
| // It is OK to call SetTaskGraph() after shutdown if |graph| is empty. |
| DCHECK(graph->empty() || !shutdown_); |
| - GraphNodeMap new_pending_tasks; |
| - GraphNodeMap new_running_tasks; |
| + TaskGraph new_pending_tasks; |
| + TaskGraph new_running_tasks; |
| TaskQueue new_ready_to_run_tasks; |
| + TaskNamespaceQueue new_ready_to_run_namespaces; |
| new_pending_tasks.swap(*graph); |
| { |
| base::AutoLock lock(lock_); |
| + DCHECK(namespaces_.find(worker_pool) != namespaces_.end()); |
| + TaskNamespace* task_namespace = namespaces_[worker_pool].get(); |
| + |
| // First remove all completed tasks from |new_pending_tasks| and |
| // adjust number of dependencies. |
| - for (TaskVector::iterator it = completed_tasks_.begin(); |
| - it != completed_tasks_.end(); ++it) { |
| + for (TaskVector::iterator it = task_namespace->completed_tasks.begin(); |
| + it != task_namespace->completed_tasks.end(); ++it) { |
| internal::WorkerPoolTask* task = it->get(); |
| scoped_ptr<internal::GraphNode> node = new_pending_tasks.take_and_erase( |
| @@ -239,8 +259,8 @@ void WorkerPool::Inner::SetTaskGraph(TaskGraph* graph) { |
| } |
| // Build new running task set. |
| - for (GraphNodeMap::iterator it = running_tasks_.begin(); |
| - it != running_tasks_.end(); ++it) { |
| + for (TaskGraph::iterator it = task_namespace->running_tasks.begin(); |
| + it != task_namespace->running_tasks.end(); ++it) { |
| internal::WorkerPoolTask* task = it->first; |
| // Transfer scheduled task value from |new_pending_tasks| to |
| // |new_running_tasks| if currently running. Value must be set to |
| @@ -251,7 +271,7 @@ void WorkerPool::Inner::SetTaskGraph(TaskGraph* graph) { |
| // Build new "ready to run" tasks queue. |
| // TODO(reveman): Create this queue when building the task graph instead. |
| - for (GraphNodeMap::iterator it = new_pending_tasks.begin(); |
| + for (TaskGraph::iterator it = new_pending_tasks.begin(); |
| it != new_pending_tasks.end(); ++it) { |
| internal::WorkerPoolTask* task = it->first; |
| DCHECK(task); |
| @@ -268,52 +288,64 @@ void WorkerPool::Inner::SetTaskGraph(TaskGraph* graph) { |
| new_ready_to_run_tasks.push(node); |
| // Erase the task from old pending tasks. |
| - pending_tasks_.erase(task); |
| + task_namespace->pending_tasks.erase(task); |
| } |
| - completed_tasks_.reserve(completed_tasks_.size() + pending_tasks_.size()); |
| + task_namespace->completed_tasks.reserve( |
| + task_namespace->completed_tasks.size() + |
| + task_namespace->pending_tasks.size()); |
| - // The items left in |pending_tasks_| need to be canceled. |
| - for (GraphNodeMap::const_iterator it = pending_tasks_.begin(); |
| - it != pending_tasks_.end(); |
| - ++it) { |
| - completed_tasks_.push_back(it->first); |
| + // The items left in |pending_tasks| need to be canceled. |
| + for (TaskGraph::const_iterator it = task_namespace->pending_tasks.begin(); |
| + it != task_namespace->pending_tasks.end(); ++it) { |
| + task_namespace->completed_tasks.push_back(it->first); |
| } |
| // Swap task sets. |
| // Note: old tasks are intentionally destroyed after releasing |lock_|. |
| - pending_tasks_.swap(new_pending_tasks); |
| - running_tasks_.swap(new_running_tasks); |
| - std::swap(ready_to_run_tasks_, new_ready_to_run_tasks); |
| + task_namespace->pending_tasks.swap(new_pending_tasks); |
| + task_namespace->running_tasks.swap(new_running_tasks); |
| + std::swap(task_namespace->ready_to_run_tasks, new_ready_to_run_tasks); |
| - // If |ready_to_run_tasks_| is empty, it means we either have |
| + // If |ready_to_run_tasks| is empty, it means we either have |
| // running tasks, or we have no pending tasks. |
| - DCHECK(!ready_to_run_tasks_.empty() || |
| - (pending_tasks_.empty() || !running_tasks_.empty())); |
| + DCHECK(!task_namespace->ready_to_run_tasks.empty() || |
| + (task_namespace->pending_tasks.empty() || |
| + !task_namespace->running_tasks.empty())); |
| + |
| + // Build new "ready to run" task namespaces queue. |
| + for (TaskNamespaceMap::iterator it = namespaces_.begin(); |
| + it != namespaces_.end(); ++it) { |
| + if (!it->second->ready_to_run_tasks.empty()) |
| + new_ready_to_run_namespaces.push(it->second.get()); |
| + } |
| + std::swap(ready_to_run_namespaces_, new_ready_to_run_namespaces); |
| // If there is more work available, wake up worker thread. |
| - if (!ready_to_run_tasks_.empty()) |
| + if (!ready_to_run_namespaces_.empty()) |
| has_ready_to_run_tasks_cv_.Signal(); |
| } |
| } |
| -void WorkerPool::Inner::CollectCompletedTasks(TaskVector* completed_tasks) { |
| +void TaskGraphRunner::CollectCompletedTasks( |
| + const WorkerPool* worker_pool, TaskVector* completed_tasks) { |
| base::AutoLock lock(lock_); |
| DCHECK_EQ(0u, completed_tasks->size()); |
| - completed_tasks->swap(completed_tasks_); |
| + DCHECK(namespaces_.find(worker_pool) != namespaces_.end()); |
| + completed_tasks->swap(namespaces_[worker_pool]->completed_tasks); |
| } |
| -void WorkerPool::Inner::Run() { |
| +void TaskGraphRunner::Run() { |
| base::AutoLock lock(lock_); |
| // Get a unique thread index. |
| int thread_index = next_thread_index_++; |
| while (true) { |
| - if (ready_to_run_tasks_.empty()) { |
| + if (ready_to_run_namespaces_.empty()) { |
| // Exit when shutdown is set and no more tasks are pending. |
| - if (shutdown_ && pending_tasks_.empty()) |
| + if (shutdown_) |
| break; |
| // Wait for more tasks. |
| @@ -321,15 +353,27 @@ void WorkerPool::Inner::Run() { |
| continue; |
| } |
| - // Take top priority task from |ready_to_run_tasks_|. |
| + // Take top priority TaskNamespace from |ready_to_run_namespaces_|. |
| + TaskNamespace* task_namespace = ready_to_run_namespaces_.top(); |
| + ready_to_run_namespaces_.pop(); |
| + DCHECK(!task_namespace->ready_to_run_tasks.empty()); |
| + |
| + // Take top priority task from |ready_to_run_tasks|. |
| scoped_refptr<internal::WorkerPoolTask> task( |
| - ready_to_run_tasks_.top()->task()); |
| - ready_to_run_tasks_.pop(); |
| + task_namespace->ready_to_run_tasks.top()->task()); |
| + task_namespace->ready_to_run_tasks.pop(); |
| - // Move task from |pending_tasks_| to |running_tasks_|. |
| - DCHECK(pending_tasks_.contains(task.get())); |
| - DCHECK(!running_tasks_.contains(task.get())); |
| - running_tasks_.set(task.get(), pending_tasks_.take_and_erase(task.get())); |
| + // Add task namespace back to |ready_to_run_namespaces_| if not |
| + // empty after taking top priority task. |
| + if (!task_namespace->ready_to_run_tasks.empty()) |
| + ready_to_run_namespaces_.push(task_namespace); |
| + |
| + // Move task from |pending_tasks| to |running_tasks|. |
| + DCHECK(task_namespace->pending_tasks.contains(task.get())); |
| + DCHECK(!task_namespace->running_tasks.contains(task.get())); |
| + task_namespace->running_tasks.set( |
| + task.get(), |
| + task_namespace->pending_tasks.take_and_erase(task.get())); |
| // There may be more work available, so wake up another worker thread. |
| has_ready_to_run_tasks_cv_.Signal(); |
| @@ -348,8 +392,8 @@ void WorkerPool::Inner::Run() { |
| // Now iterate over all dependents to remove dependency and check |
| // if they are ready to run. |
| - scoped_ptr<internal::GraphNode> node = running_tasks_.take_and_erase( |
| - task.get()); |
| + scoped_ptr<internal::GraphNode> node = |
| + task_namespace->running_tasks.take_and_erase(task.get()); |
| if (node) { |
| for (internal::GraphNode::Vector::const_iterator it = |
| node->dependents().begin(); |
| @@ -358,14 +402,25 @@ void WorkerPool::Inner::Run() { |
| dependent_node->remove_dependency(); |
| // Task is ready if it has no dependencies. Add it to |
| - // |ready_to_run_tasks_|. |
| - if (!dependent_node->num_dependencies()) |
| - ready_to_run_tasks_.push(dependent_node); |
| + // |ready_to_run_tasks|. |
| + if (!dependent_node->num_dependencies()) { |
| + bool was_empty = task_namespace->ready_to_run_tasks.empty(); |
| + task_namespace->ready_to_run_tasks.push(dependent_node); |
| + // Task namespace is ready if it has at least one ready |
| + // to run task. Add it to |ready_to_run_namespaces_| if |
| + // it just become ready. |
| + if (was_empty) |
| + ready_to_run_namespaces_.push(task_namespace); |
| + } |
| } |
| } |
| - // Finally add task to |completed_tasks_|. |
| - completed_tasks_.push_back(task); |
| + // Finally add task to |completed_tasks|. |
| + task_namespace->completed_tasks.push_back(task); |
| + |
| + // If namespace has finished running all tasks, wake up origin thread. |
| + if (has_finished_running_tasks(task_namespace)) |
| + has_namespaces_with_finished_running_tasks_cv_.Signal(); |
| } |
| // We noticed we should exit. Wake up the next worker so it knows it should |
| @@ -373,13 +428,84 @@ void WorkerPool::Inner::Run() { |
| has_ready_to_run_tasks_cv_.Signal(); |
| } |
| -WorkerPool::WorkerPool(size_t num_threads, |
| - const std::string& thread_name_prefix) |
| - : in_dispatch_completion_callbacks_(false), |
| - inner_(make_scoped_ptr(new Inner(num_threads, thread_name_prefix))) { |
| +class CC_EXPORT CompositorRasterTaskGraphRunner |
| + : public TaskGraphRunner { |
| + public: |
| + CompositorRasterTaskGraphRunner() : TaskGraphRunner( |
| + switches::GetNumRasterThreads(), "CompositorRaster") { |
| + } |
| +}; |
| + |
| +base::LazyInstance<CompositorRasterTaskGraphRunner> |
| + g_task_graph_runner = LAZY_INSTANCE_INITIALIZER; |
| + |
| +} // namespace |
| + |
| +namespace internal { |
| + |
| +WorkerPoolTask::WorkerPoolTask() |
| + : did_schedule_(false), |
| + did_run_(false), |
| + did_complete_(false) { |
| +} |
| + |
| +WorkerPoolTask::~WorkerPoolTask() { |
| + DCHECK_EQ(did_schedule_, did_complete_); |
| + DCHECK(!did_run_ || did_schedule_); |
| + DCHECK(!did_run_ || did_complete_); |
| +} |
| + |
| +void WorkerPoolTask::DidSchedule() { |
| + DCHECK(!did_complete_); |
| + did_schedule_ = true; |
| +} |
| + |
| +void WorkerPoolTask::WillRun() { |
| + DCHECK(did_schedule_); |
| + DCHECK(!did_complete_); |
| + DCHECK(!did_run_); |
| +} |
| + |
| +void WorkerPoolTask::DidRun() { |
| + did_run_ = true; |
| +} |
| + |
| +void WorkerPoolTask::WillComplete() { |
| + DCHECK(!did_complete_); |
| +} |
| + |
| +void WorkerPoolTask::DidComplete() { |
| + DCHECK(did_schedule_); |
| + DCHECK(!did_complete_); |
| + did_complete_ = true; |
| +} |
| + |
| +bool WorkerPoolTask::HasFinishedRunning() const { |
| + return did_run_; |
| +} |
| + |
| +bool WorkerPoolTask::HasCompleted() const { |
| + return did_complete_; |
| +} |
| + |
| +GraphNode::GraphNode(internal::WorkerPoolTask* task, unsigned priority) |
| + : task_(task), |
| + priority_(priority), |
| + num_dependencies_(0) { |
| +} |
| + |
| +GraphNode::~GraphNode() { |
| +} |
| + |
| +} // namespace internal |
| + |
| +WorkerPool::WorkerPool() |
| + : in_dispatch_completion_callbacks_(false) { |
|
reveman
2013/12/28 14:45:48
nit: this will fit on previous line.
sohanjg
2013/12/30 06:49:36
Done.
|
| + g_task_graph_runner.Pointer()->Register(this); |
| } |
| WorkerPool::~WorkerPool() { |
| + g_task_graph_runner.Pointer()->Unregister(this); |
| } |
| void WorkerPool::Shutdown() { |
| @@ -387,7 +513,7 @@ void WorkerPool::Shutdown() { |
| DCHECK(!in_dispatch_completion_callbacks_); |
| - inner_->Shutdown(); |
| + g_task_graph_runner.Pointer()->WaitForTasksToFinishRunning(this); |
| } |
| void WorkerPool::CheckForCompletedTasks() { |
| @@ -396,7 +522,7 @@ void WorkerPool::CheckForCompletedTasks() { |
| DCHECK(!in_dispatch_completion_callbacks_); |
| TaskVector completed_tasks; |
| - inner_->CollectCompletedTasks(&completed_tasks); |
| + g_task_graph_runner.Pointer()->CollectCompletedTasks(this, &completed_tasks); |
| ProcessCompletedTasks(completed_tasks); |
| } |
| @@ -427,7 +553,7 @@ void WorkerPool::SetTaskGraph(TaskGraph* graph) { |
| DCHECK(!in_dispatch_completion_callbacks_); |
| - inner_->SetTaskGraph(graph); |
| + g_task_graph_runner.Pointer()->SetTaskGraph(this, graph); |
| } |
| } // namespace cc |