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

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

Issue 1854723002: cc: Simplify task and its derived classes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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"
(...skipping 25 matching lines...) Expand all
36 // Overridden from base::TaskRunner: 36 // Overridden from base::TaskRunner:
37 bool PostDelayedTask(const tracked_objects::Location& from_here, 37 bool PostDelayedTask(const tracked_objects::Location& from_here,
38 const base::Closure& task, 38 const base::Closure& task,
39 base::TimeDelta delay) override; 39 base::TimeDelta delay) override;
40 bool RunsTasksOnCurrentThread() const override; 40 bool RunsTasksOnCurrentThread() const override;
41 41
42 // Overridden from cc::TaskGraphRunner: 42 // Overridden from cc::TaskGraphRunner:
43 cc::NamespaceToken GetNamespaceToken() override; 43 cc::NamespaceToken GetNamespaceToken() override;
44 void ScheduleTasks(cc::NamespaceToken token, cc::TaskGraph* graph) override; 44 void ScheduleTasks(cc::NamespaceToken token, cc::TaskGraph* graph) override;
45 void WaitForTasksToFinishRunning(cc::NamespaceToken token) override; 45 void WaitForTasksToFinishRunning(cc::NamespaceToken token) override;
46 void CollectCompletedTasks(cc::NamespaceToken token, 46 void CollectCompletedTasks(
47 cc::Task::Vector* completed_tasks) override; 47 cc::NamespaceToken token,
48 cc::DependencyTask::Vector* completed_tasks) override;
48 49
49 // Runs a task from one of the provided categories. Categories listed first 50 // Runs a task from one of the provided categories. Categories listed first
50 // have higher priority. 51 // have higher priority.
51 void Run(const std::vector<cc::TaskCategory>& categories, 52 void Run(const std::vector<cc::TaskCategory>& categories,
52 base::ConditionVariable* has_ready_to_run_tasks_cv); 53 base::ConditionVariable* has_ready_to_run_tasks_cv);
53 54
54 void FlushForTesting(); 55 void FlushForTesting();
55 56
56 // Spawn |num_threads| number of threads and start running work on the 57 // Spawn |num_threads| number of threads and start running work on the
57 // worker threads. 58 // worker threads.
(...skipping 13 matching lines...) Expand all
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 // Simple Task for the TaskGraphRunner that wraps a closure. 79 // Simple Task for the TaskGraphRunner that wraps a closure.
79 // This class is used to schedule TaskRunner tasks on the 80 // This class is used to schedule TaskRunner tasks on the
80 // |task_graph_runner_|. 81 // |task_graph_runner_|.
81 class ClosureTask : public cc::Task { 82 class ClosureTask : public cc::DependencyTask {
82 public: 83 public:
83 explicit ClosureTask(const base::Closure& closure); 84 explicit ClosureTask(const base::Closure& closure);
84 85
85 // Overridden from cc::Task: 86 // Overridden from cc::DependencyTask:
87 void ScheduleOnOriginThread(cc::DependencyTaskClient* client) override{};
88 void CompleteOnOriginThread(cc::DependencyTaskClient* client) override{};
86 void RunOnWorkerThread() override; 89 void RunOnWorkerThread() override;
87 90
88 protected: 91 protected:
89 ~ClosureTask() override; 92 ~ClosureTask() override;
90 93
91 private: 94 private:
92 base::Closure closure_; 95 base::Closure closure_;
93 96
94 DISALLOW_COPY_AND_ASSIGN(ClosureTask); 97 DISALLOW_COPY_AND_ASSIGN(ClosureTask);
95 }; 98 };
96 99
97 void ScheduleTasksWithLockAcquired(cc::NamespaceToken token, 100 void ScheduleTasksWithLockAcquired(cc::NamespaceToken token,
98 cc::TaskGraph* graph); 101 cc::TaskGraph* graph);
99 void CollectCompletedTasksWithLockAcquired(cc::NamespaceToken token, 102 void CollectCompletedTasksWithLockAcquired(
100 cc::Task::Vector* completed_tasks); 103 cc::NamespaceToken token,
104 cc::DependencyTask::Vector* completed_tasks);
101 105
102 // Runs a task from one of the provided categories. Categories listed first 106 // Runs a task from one of the provided categories. Categories listed first
103 // have higher priority. Returns false if there were no tasks to run. 107 // have higher priority. Returns false if there were no tasks to run.
104 bool RunTaskWithLockAcquired(const std::vector<cc::TaskCategory>& categories); 108 bool RunTaskWithLockAcquired(const std::vector<cc::TaskCategory>& categories);
105 109
106 // Run next task for the given category. Caller must acquire |lock_| prior to 110 // Run next task for the given category. Caller must acquire |lock_| prior to
107 // calling this function and make sure at least one task is ready to run. 111 // calling this function and make sure at least one task is ready to run.
108 void RunTaskInCategoryWithLockAcquired(cc::TaskCategory category); 112 void RunTaskInCategoryWithLockAcquired(cc::TaskCategory category);
109 113
110 // Helper function which signals worker threads if tasks are ready to run. 114 // Helper function which signals worker threads if tasks are ready to run.
111 void SignalHasReadyToRunTasksWithLockAcquired(); 115 void SignalHasReadyToRunTasksWithLockAcquired();
112 116
113 // Determines if we should run a new task for the given category. This factors 117 // Determines if we should run a new task for the given category. This factors
114 // in whether a task is available and whether the count of running tasks is 118 // in whether a task is available and whether the count of running tasks is
115 // low enough to start a new one. 119 // low enough to start a new one.
116 bool ShouldRunTaskForCategoryWithLockAcquired(cc::TaskCategory category); 120 bool ShouldRunTaskForCategoryWithLockAcquired(cc::TaskCategory category);
117 121
118 // The actual threads where work is done. 122 // The actual threads where work is done.
119 std::vector<scoped_ptr<base::SimpleThread>> threads_; 123 std::vector<scoped_ptr<base::SimpleThread>> threads_;
120 124
121 // Lock to exclusively access all the following members that are used to 125 // Lock to exclusively access all the following members that are used to
122 // implement the TaskRunner and TaskGraphRunner interfaces. 126 // implement the TaskRunner and TaskGraphRunner interfaces.
123 base::Lock lock_; 127 base::Lock lock_;
124 // Stores the tasks to be run, sorted by priority. 128 // Stores the tasks to be run, sorted by priority.
125 cc::TaskGraphWorkQueue work_queue_; 129 cc::TaskGraphWorkQueue work_queue_;
126 // Namespace used to schedule tasks in the task graph runner. 130 // Namespace used to schedule tasks in the task graph runner.
127 cc::NamespaceToken namespace_token_; 131 cc::NamespaceToken namespace_token_;
128 // List of tasks currently queued up for execution. 132 // List of tasks currently queued up for execution.
129 cc::Task::Vector tasks_; 133 cc::DependencyTask::Vector tasks_;
130 // Graph object used for scheduling tasks. 134 // Graph object used for scheduling tasks.
131 cc::TaskGraph graph_; 135 cc::TaskGraph graph_;
132 // Cached vector to avoid allocation when getting the list of complete 136 // Cached vector to avoid allocation when getting the list of complete
133 // tasks. 137 // tasks.
134 cc::Task::Vector completed_tasks_; 138 cc::DependencyTask::Vector completed_tasks_;
135 // Condition variables for foreground and background tasks. 139 // Condition variables for foreground and background tasks.
136 base::ConditionVariable has_ready_to_run_foreground_tasks_cv_; 140 base::ConditionVariable has_ready_to_run_foreground_tasks_cv_;
137 base::ConditionVariable has_ready_to_run_background_tasks_cv_; 141 base::ConditionVariable has_ready_to_run_background_tasks_cv_;
138 // Condition variable that is waited on by origin threads until a namespace 142 // Condition variable that is waited on by origin threads until a namespace
139 // has finished running all associated tasks. 143 // has finished running all associated tasks.
140 base::ConditionVariable has_namespaces_with_finished_running_tasks_cv_; 144 base::ConditionVariable has_namespaces_with_finished_running_tasks_cv_;
141 // Set during shutdown. Tells Run() to return when no more tasks are pending. 145 // Set during shutdown. Tells Run() to return when no more tasks are pending.
142 bool shutdown_; 146 bool shutdown_;
143 }; 147 };
144 148
145 } // namespace content 149 } // namespace content
146 150
147 #endif // CONTENT_RENDERER_RASTER_WORKER_POOL_H_ 151 #endif // CONTENT_RENDERER_RASTER_WORKER_POOL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698