Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 30 matching lines...) Expand all Loading... | |
| 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(cc::NamespaceToken token, |
| 47 cc::Task::Vector* completed_tasks) override; | 47 cc::Task::Vector* completed_tasks) override; |
| 48 | 48 |
| 49 // Runs a task from one of the provided categories. Categories listed first | 49 // Runs a task from one of the provided categories. Categories listed first |
| 50 // have higher priority. | 50 // have higher priority. |
| 51 void Run(const std::vector<cc::TaskCategory>& categories); | 51 void Run(const std::vector<cc::TaskCategory>& categories, |
| 52 base::ConditionVariable* work_ready_cv); | |
|
reveman
2016/02/10 23:25:09
nit: s/work_ready_cv/has_ready_to_run_tasks_cv/
ericrk
2016/02/11 00:22:02
Done.
| |
| 52 | 53 |
| 53 void FlushForTesting(); | 54 void FlushForTesting(); |
| 54 | 55 |
| 55 // Spawn |num_threads| number of threads and start running work on the | 56 // Spawn |num_threads| number of threads and start running work on the |
| 56 // worker threads. | 57 // worker threads. |
| 57 void Start(int num_threads, | 58 void Start(int num_threads, |
| 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. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 | 96 |
| 96 protected: | 97 protected: |
| 97 ~ClosureTask() override; | 98 ~ClosureTask() override; |
| 98 | 99 |
| 99 private: | 100 private: |
| 100 base::Closure closure_; | 101 base::Closure closure_; |
| 101 | 102 |
| 102 DISALLOW_COPY_AND_ASSIGN(ClosureTask); | 103 DISALLOW_COPY_AND_ASSIGN(ClosureTask); |
| 103 }; | 104 }; |
| 104 | 105 |
| 106 // Helper function which signals the CV for the next task to run. | |
|
reveman
2016/02/10 23:25:09
nit: "...signals the worker threads if tasks are r
ericrk
2016/02/11 00:22:02
Done.
| |
| 107 void SignalHasReadyToRunTasksWithLockAcquired(); | |
| 108 | |
| 109 // Determines if we should run a new task for the given category. This factors | |
| 110 // in whether a task is available and whether the count of running tasks is | |
| 111 // low enough to start a new one. | |
| 112 bool ShouldRunTaskForCategoryWithLockAcquired(cc::TaskCategory category); | |
|
reveman
2016/02/10 23:25:09
nit: move these functions so the order and locatio
ericrk
2016/02/11 00:22:02
Done.
| |
| 113 | |
| 105 void ScheduleTasksWithLockAcquired(cc::NamespaceToken token, | 114 void ScheduleTasksWithLockAcquired(cc::NamespaceToken token, |
| 106 cc::TaskGraph* graph); | 115 cc::TaskGraph* graph); |
| 107 void CollectCompletedTasksWithLockAcquired(cc::NamespaceToken token, | 116 void CollectCompletedTasksWithLockAcquired(cc::NamespaceToken token, |
| 108 cc::Task::Vector* completed_tasks); | 117 cc::Task::Vector* completed_tasks); |
| 109 | 118 |
| 110 // The actual threads where work is done. | 119 // The actual threads where work is done. |
| 111 std::vector<scoped_ptr<base::SimpleThread>> threads_; | 120 std::vector<scoped_ptr<base::SimpleThread>> threads_; |
| 112 | 121 |
| 113 // Lock to exclusively access all the following members that are used to | 122 // Lock to exclusively access all the following members that are used to |
| 114 // implement the TaskRunner and TaskGraphRunner interfaces. | 123 // implement the TaskRunner and TaskGraphRunner interfaces. |
| 115 base::Lock lock_; | 124 base::Lock lock_; |
| 116 // Stores the tasks to be run, sorted by priority. | 125 // Stores the tasks to be run, sorted by priority. |
| 117 cc::TaskGraphWorkQueue work_queue_; | 126 cc::TaskGraphWorkQueue work_queue_; |
| 118 // Namespace used to schedule tasks in the task graph runner. | 127 // Namespace used to schedule tasks in the task graph runner. |
| 119 cc::NamespaceToken namespace_token_; | 128 cc::NamespaceToken namespace_token_; |
| 120 // List of tasks currently queued up for execution. | 129 // List of tasks currently queued up for execution. |
| 121 cc::Task::Vector tasks_; | 130 cc::Task::Vector tasks_; |
| 122 // Graph object used for scheduling tasks. | 131 // Graph object used for scheduling tasks. |
| 123 cc::TaskGraph graph_; | 132 cc::TaskGraph graph_; |
| 124 // Cached vector to avoid allocation when getting the list of complete | 133 // Cached vector to avoid allocation when getting the list of complete |
| 125 // tasks. | 134 // tasks. |
| 126 cc::Task::Vector completed_tasks_; | 135 cc::Task::Vector completed_tasks_; |
| 127 // Condition variable that is waited on by Run() until new tasks are ready to | 136 // Condition variables for foreground and background tasks. |
| 128 // run or shutdown starts. | 137 base::ConditionVariable foreground_has_ready_to_run_tasks_cv_; |
|
reveman
2016/02/10 23:25:09
nit: s/foreground_has_ready_to_run_tasks_cv_/has_r
ericrk
2016/02/11 00:22:02
Done.
| |
| 129 base::ConditionVariable has_ready_to_run_tasks_cv_; | 138 base::ConditionVariable background_has_ready_to_run_tasks_cv_; |
|
reveman
2016/02/10 23:25:09
nit: s/background_has_ready_to_run_tasks_cv_/has_r
ericrk
2016/02/11 00:22:02
Done.
| |
| 130 // Condition variable that is waited on by origin threads until a namespace | 139 // Condition variable that is waited on by origin threads until a namespace |
| 131 // has finished running all associated tasks. | 140 // has finished running all associated tasks. |
| 132 base::ConditionVariable has_namespaces_with_finished_running_tasks_cv_; | 141 base::ConditionVariable has_namespaces_with_finished_running_tasks_cv_; |
| 133 // Set during shutdown. Tells Run() to return when no more tasks are pending. | 142 // Set during shutdown. Tells Run() to return when no more tasks are pending. |
| 134 bool shutdown_; | 143 bool shutdown_; |
| 135 }; | 144 }; |
| 136 | 145 |
| 137 } // namespace content | 146 } // namespace content |
| 138 | 147 |
| 139 #endif // CONTENT_RENDERER_RASTER_WORKER_POOL_H_ | 148 #endif // CONTENT_RENDERER_RASTER_WORKER_POOL_H_ |
| OLD | NEW |