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

Side by Side Diff: content/renderer/raster_worker_pool.h

Issue 1576133002: Add category handling to RasterWorkerPool (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@hihi
Patch Set: Created 4 years, 11 months 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #ifndef CONTENT_RENDERER_RASTER_WORKER_POOL_H_ 5 #ifndef CONTENT_RENDERER_RASTER_WORKER_POOL_H_
6 #define CONTENT_RENDERER_RASTER_WORKER_POOL_H_ 6 #define CONTENT_RENDERER_RASTER_WORKER_POOL_H_
7 7
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/containers/hash_tables.h" 9 #include "base/containers/hash_tables.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/memory/scoped_vector.h" 11 #include "base/memory/scoped_vector.h"
12 #include "base/sequenced_task_runner.h" 12 #include "base/sequenced_task_runner.h"
13 #include "base/synchronization/condition_variable.h" 13 #include "base/synchronization/condition_variable.h"
14 #include "base/task_runner.h" 14 #include "base/task_runner.h"
15 #include "base/threading/simple_thread.h" 15 #include "base/threading/simple_thread.h"
16 #include "cc/raster/task_category.h"
16 #include "cc/raster/task_graph_runner.h" 17 #include "cc/raster/task_graph_runner.h"
17 #include "cc/raster/task_graph_work_queue.h" 18 #include "cc/raster/task_graph_work_queue.h"
18 #include "content/common/content_export.h" 19 #include "content/common/content_export.h"
19 20
20 namespace content { 21 namespace content {
21 22
22 // A pool of threads used to run raster work. 23 // A pool of threads used to run raster work.
23 // Work can be scheduled on the threads using different interfaces. 24 // Work can be scheduled on the threads using different interfaces.
24 // The pool itself implements TaskRunner interface and tasks posted via that 25 // The pool itself implements TaskRunner interface and tasks posted via that
25 // interface might run in parallel. 26 // interface might run in parallel.
26 // CreateSequencedTaskRunner creates a sequenced task runner that might run in 27 // CreateSequencedTaskRunner creates a sequenced task runner that might run in
27 // parallel with other instances of sequenced task runners. 28 // parallel with other instances of sequenced task runners.
28 // It's also possible to get the underlying TaskGraphRunner to schedule a graph 29 // It's also possible to get the underlying TaskGraphRunner to schedule a graph
29 // of tasks with their dependencies. 30 // of tasks with their dependencies.
30 class CONTENT_EXPORT RasterWorkerPool 31 class CONTENT_EXPORT RasterWorkerPool : public base::TaskRunner,
31 : public base::TaskRunner, 32 public cc::TaskGraphRunner {
32 public cc::TaskGraphRunner,
33 public base::DelegateSimpleThread::Delegate {
34 public: 33 public:
35 RasterWorkerPool(); 34 RasterWorkerPool();
36 35
37 // Overridden from base::TaskRunner: 36 // Overridden from base::TaskRunner:
38 bool PostDelayedTask(const tracked_objects::Location& from_here, 37 bool PostDelayedTask(const tracked_objects::Location& from_here,
39 const base::Closure& task, 38 const base::Closure& task,
40 base::TimeDelta delay) override; 39 base::TimeDelta delay) override;
41 bool RunsTasksOnCurrentThread() const override; 40 bool RunsTasksOnCurrentThread() const override;
42 41
43 // Overridden from cc::TaskGraphRunner: 42 // Overridden from cc::TaskGraphRunner:
44 cc::NamespaceToken GetNamespaceToken() override; 43 cc::NamespaceToken GetNamespaceToken() override;
45 void ScheduleTasks(cc::NamespaceToken token, cc::TaskGraph* graph) override; 44 void ScheduleTasks(cc::NamespaceToken token, cc::TaskGraph* graph) override;
46 void WaitForTasksToFinishRunning(cc::NamespaceToken token) override; 45 void WaitForTasksToFinishRunning(cc::NamespaceToken token) override;
47 void CollectCompletedTasks(cc::NamespaceToken token, 46 void CollectCompletedTasks(cc::NamespaceToken token,
48 cc::Task::Vector* completed_tasks) override; 47 cc::Task::Vector* completed_tasks) override;
49 48
50 // Overridden from base::DelegateSimpleThread::Delegate: 49 // Runs a task from one of the provided categories. Categories listed first
51 void Run() override; 50 // have higher priority.
51 void Run(const std::vector<cc::TaskCategory>& categories);
52 52
53 void FlushForTesting(); 53 void FlushForTesting();
54 54
55 // Spawn |num_threads| number of threads and start running work on the 55 // Spawn |num_threads| number of threads and start running work on the
56 // worker threads. 56 // worker threads.
57 void Start(int num_threads, 57 void Start(int num_threads,
58 bool use_single_thread_for_background_raster_tasks,
58 const base::SimpleThread::Options& thread_options); 59 const base::SimpleThread::Options& thread_options);
59 60
60 // Finish running all the posted tasks (and nested task posted by those tasks) 61 // Finish running all the posted tasks (and nested task posted by those tasks)
61 // of all the associated task runners. 62 // of all the associated task runners.
62 // Once all the tasks are executed the method blocks until the threads are 63 // Once all the tasks are executed the method blocks until the threads are
63 // terminated. 64 // terminated.
64 void Shutdown(); 65 void Shutdown();
65 66
66 cc::TaskGraphRunner* GetTaskGraphRunner() { return this; } 67 cc::TaskGraphRunner* GetTaskGraphRunner() { return this; }
67 68
68 // Create a new sequenced task graph runner. 69 // Create a new sequenced task graph runner.
69 scoped_refptr<base::SequencedTaskRunner> CreateSequencedTaskRunner(); 70 scoped_refptr<base::SequencedTaskRunner> CreateSequencedTaskRunner();
70 71
71 protected: 72 protected:
72 ~RasterWorkerPool() override; 73 ~RasterWorkerPool() override;
73 74
74 private: 75 private:
75 class RasterWorkerPoolSequencedTaskRunner; 76 class RasterWorkerPoolSequencedTaskRunner;
76 friend class RasterWorkerPoolSequencedTaskRunner; 77 friend class RasterWorkerPoolSequencedTaskRunner;
77 78
78 // Run next task. Caller must acquire |lock_| prior to calling this function. 79 // Run next task. Caller must acquire |lock_| prior to calling this function
79 // Returns true if there was a task available to run. 80 // and make sure at least one task is ready to run.
80 bool RunTaskWithLockAcquired(); 81 void RunTaskWithLockAcquired(cc::TaskCategory category);
81 82
82 // Simple Task for the TaskGraphRunner that wraps a closure. 83 // Simple Task for the TaskGraphRunner that wraps a closure.
83 // This class is used to schedule TaskRunner tasks on the 84 // This class is used to schedule TaskRunner tasks on the
84 // |task_graph_runner_|. 85 // |task_graph_runner_|.
85 class ClosureTask : public cc::Task { 86 class ClosureTask : public cc::Task {
86 public: 87 public:
87 explicit ClosureTask(const base::Closure& closure); 88 explicit ClosureTask(const base::Closure& closure);
88 89
89 // Overridden from cc::Task: 90 // Overridden from cc::Task:
90 void RunOnWorkerThread() override; 91 void RunOnWorkerThread() override;
91 92
92 protected: 93 protected:
93 ~ClosureTask() override; 94 ~ClosureTask() override;
94 95
95 private: 96 private:
96 base::Closure closure_; 97 base::Closure closure_;
97 98
98 DISALLOW_COPY_AND_ASSIGN(ClosureTask); 99 DISALLOW_COPY_AND_ASSIGN(ClosureTask);
99 }; 100 };
100 101
101 void ScheduleTasksWithLockAcquired(cc::NamespaceToken token, 102 void ScheduleTasksWithLockAcquired(cc::NamespaceToken token,
102 cc::TaskGraph* graph); 103 cc::TaskGraph* graph);
103 void CollectCompletedTasksWithLockAcquired(cc::NamespaceToken token, 104 void CollectCompletedTasksWithLockAcquired(cc::NamespaceToken token,
104 cc::Task::Vector* completed_tasks); 105 cc::Task::Vector* completed_tasks);
105 106
106 // The actual threads where work is done. 107 // The actual threads where work is done.
107 ScopedVector<base::DelegateSimpleThread> threads_; 108 std::vector<scoped_ptr<base::SimpleThread>> threads_;
108 109
109 // Lock to exclusively access all the following members that are used to 110 // Lock to exclusively access all the following members that are used to
110 // implement the TaskRunner and TaskGraphRunner interfaces. 111 // implement the TaskRunner and TaskGraphRunner interfaces.
111 base::Lock lock_; 112 base::Lock lock_;
112 // Stores the tasks to be run, sorted by priority. 113 // Stores the tasks to be run, sorted by priority.
113 cc::TaskGraphWorkQueue work_queue_; 114 cc::TaskGraphWorkQueue work_queue_;
114 // Namespace used to schedule tasks in the task graph runner. 115 // Namespace used to schedule tasks in the task graph runner.
115 cc::NamespaceToken namespace_token_; 116 cc::NamespaceToken namespace_token_;
116 // List of tasks currently queued up for execution. 117 // List of tasks currently queued up for execution.
117 cc::Task::Vector tasks_; 118 cc::Task::Vector tasks_;
118 // Graph object used for scheduling tasks. 119 // Graph object used for scheduling tasks.
119 cc::TaskGraph graph_; 120 cc::TaskGraph graph_;
120 // Cached vector to avoid allocation when getting the list of complete 121 // Cached vector to avoid allocation when getting the list of complete
121 // tasks. 122 // tasks.
122 cc::Task::Vector completed_tasks_; 123 cc::Task::Vector completed_tasks_;
123 // Condition variable that is waited on by Run() until new tasks are ready to 124 // Condition variable that is waited on by Run() until new tasks are ready to
124 // run or shutdown starts. 125 // run or shutdown starts.
125 base::ConditionVariable has_ready_to_run_tasks_cv_; 126 base::ConditionVariable has_ready_to_run_tasks_cv_;
126 // Condition variable that is waited on by origin threads until a namespace 127 // Condition variable that is waited on by origin threads until a namespace
127 // has finished running all associated tasks. 128 // has finished running all associated tasks.
128 base::ConditionVariable has_namespaces_with_finished_running_tasks_cv_; 129 base::ConditionVariable has_namespaces_with_finished_running_tasks_cv_;
129 // Set during shutdown. Tells Run() to return when no more tasks are pending. 130 // Set during shutdown. Tells Run() to return when no more tasks are pending.
130 bool shutdown_; 131 bool shutdown_;
131 }; 132 };
132 133
133 } // namespace content 134 } // namespace content
134 135
135 #endif // CONTENT_RENDERER_RASTER_WORKER_POOL_H_ 136 #endif // CONTENT_RENDERER_RASTER_WORKER_POOL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698