Index: content/renderer/raster_worker_pool.h |
diff --git a/content/renderer/raster_worker_pool.h b/content/renderer/raster_worker_pool.h |
index b8b4f358f2f2497dd9d5a6ad4f3a9efdab696386..547eeb8609fae6f23e48216f7a570bc872c14027 100644 |
--- a/content/renderer/raster_worker_pool.h |
+++ b/content/renderer/raster_worker_pool.h |
@@ -9,9 +9,11 @@ |
#include "base/containers/hash_tables.h" |
#include "base/memory/scoped_vector.h" |
#include "base/sequenced_task_runner.h" |
+#include "base/synchronization/condition_variable.h" |
#include "base/task_runner.h" |
#include "base/threading/simple_thread.h" |
#include "cc/raster/task_graph_runner.h" |
+#include "cc/raster/task_graph_work_queue.h" |
#include "content/common/content_export.h" |
namespace content { |
@@ -24,10 +26,9 @@ namespace content { |
// parallel with other instances of sequenced task runners. |
// It's also possible to get the underlying TaskGraphRunner to schedule a graph |
// of tasks with their dependencies. |
-// TODO(reveman): make TaskGraphRunner an abstract interface and have this |
-// WorkerPool class implement it. |
class CONTENT_EXPORT RasterWorkerPool |
: public base::TaskRunner, |
+ public cc::TaskGraphRunner, |
public base::DelegateSimpleThread::Delegate { |
public: |
RasterWorkerPool(); |
@@ -38,9 +39,18 @@ class CONTENT_EXPORT RasterWorkerPool |
base::TimeDelta delay) override; |
bool RunsTasksOnCurrentThread() const override; |
+ // Overridden from cc::TaskGraphRunner: |
+ cc::NamespaceToken GetNamespaceToken() override; |
+ void ScheduleTasks(cc::NamespaceToken token, cc::TaskGraph* graph) override; |
+ void WaitForTasksToFinishRunning(cc::NamespaceToken token) override; |
+ void CollectCompletedTasks(cc::NamespaceToken token, |
+ cc::Task::Vector* completed_tasks) override; |
+ |
// Overridden from base::DelegateSimpleThread::Delegate: |
void Run() override; |
+ void FlushForTesting(); |
+ |
// Spawn |num_threads| number of threads and start running work on the |
// worker threads. |
void Start(int num_threads, |
@@ -52,7 +62,7 @@ class CONTENT_EXPORT RasterWorkerPool |
// terminated. |
void Shutdown(); |
- cc::TaskGraphRunner* GetTaskGraphRunner() { return &task_graph_runner_; } |
+ cc::TaskGraphRunner* GetTaskGraphRunner() { return this; } |
// Create a new sequenced task graph runner. |
scoped_refptr<base::SequencedTaskRunner> CreateSequencedTaskRunner(); |
@@ -64,6 +74,10 @@ class CONTENT_EXPORT RasterWorkerPool |
class RasterWorkerPoolSequencedTaskRunner; |
friend class RasterWorkerPoolSequencedTaskRunner; |
+ // Run next task. Caller must acquire |lock_| prior to calling this function |
+ // and make sure at least one task is ready to run. |
+ void RunTaskWithLockAcquired(); |
+ |
// Simple Task for the TaskGraphRunner that wraps a closure. |
// This class is used to schedule TaskRunner tasks on the |
// |task_graph_runner_|. |
@@ -83,13 +97,19 @@ class CONTENT_EXPORT RasterWorkerPool |
DISALLOW_COPY_AND_ASSIGN(ClosureTask); |
}; |
+ void ScheduleTasksWithLockAcquired(cc::NamespaceToken token, |
+ cc::TaskGraph* graph); |
+ void CollectCompletedTasksWithLockAcquired(cc::NamespaceToken token, |
+ cc::Task::Vector* completed_tasks); |
+ |
// The actual threads where work is done. |
ScopedVector<base::DelegateSimpleThread> threads_; |
- cc::TaskGraphRunner task_graph_runner_; |
// Lock to exclusively access all the following members that are used to |
- // implement the TaskRunner interfaces. |
+ // implement the TaskRunner and TaskGraphRunner interfaces. |
base::Lock lock_; |
+ // Stores the tasks to be run, sorted by priority. |
+ cc::TaskGraphWorkQueue work_queue_; |
// Namespace used to schedule tasks in the task graph runner. |
cc::NamespaceToken namespace_token_; |
// List of tasks currently queued up for execution. |
@@ -99,6 +119,14 @@ class CONTENT_EXPORT RasterWorkerPool |
// Cached vector to avoid allocation when getting the list of complete |
// tasks. |
cc::Task::Vector completed_tasks_; |
+ // Condition variable that is waited on by Run() until new 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_; |
+ // Set during shutdown. Tells Run() to return when no more tasks are pending. |
+ bool shutdown_; |
}; |
} // namespace content |