OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 CC_WORKER_POOL_H_ | 5 #ifndef CC_WORKER_POOL_H_ |
6 #define CC_WORKER_POOL_H_ | 6 #define CC_WORKER_POOL_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "base/threading/thread.h" | 14 #include "base/threading/thread.h" |
15 #include "cc/rendering_stats.h" | 15 #include "cc/rendering_stats.h" |
16 #include "cc/scoped_ptr_deque.h" | 16 #include "cc/scoped_ptr_deque.h" |
17 | 17 |
18 namespace cc { | 18 namespace cc { |
19 namespace internal { | 19 namespace internal { |
20 | 20 |
21 class WorkerPoolTask { | 21 class WorkerPoolTask { |
22 public: | 22 public: |
23 virtual ~WorkerPoolTask(); | 23 virtual ~WorkerPoolTask(); |
24 | 24 |
25 virtual void Run(RenderingStats* rendering_stats) = 0; | 25 virtual void Run(RenderingStats* rendering_stats) = 0; |
26 | 26 |
27 virtual void DeferToThread(base::Thread* thread) = 0; | |
28 | |
27 void Completed(); | 29 void Completed(); |
28 | 30 |
29 protected: | 31 protected: |
30 WorkerPoolTask(const base::Closure& reply); | 32 WorkerPoolTask(const base::Closure& reply); |
31 | 33 |
32 base::Closure reply_; | 34 base::Closure reply_; |
33 }; | 35 }; |
34 | 36 |
35 } // namespace internal | 37 } // namespace internal |
36 | 38 |
(...skipping 20 matching lines...) Expand all Loading... | |
57 // Returns true when worker pool has reached its internal limit for number | 59 // Returns true when worker pool has reached its internal limit for number |
58 // of pending tasks. | 60 // of pending tasks. |
59 bool IsBusy(); | 61 bool IsBusy(); |
60 | 62 |
61 // Toggle rendering stats collection. | 63 // Toggle rendering stats collection. |
62 void SetRecordRenderingStats(bool record_rendering_stats); | 64 void SetRecordRenderingStats(bool record_rendering_stats); |
63 | 65 |
64 // Collect rendering stats all completed tasks. | 66 // Collect rendering stats all completed tasks. |
65 void GetRenderingStats(RenderingStats* stats); | 67 void GetRenderingStats(RenderingStats* stats); |
66 | 68 |
69 // Run cheap, low latency tasks on the main thread. If the pending cheap tasks | |
70 // take too long to run, the remaining ones are deferred to the worker | |
71 // threads. Returns true if any cheap tasks were run. | |
72 bool RunCheapTasks(); | |
73 | |
74 // Control whether cheap (main thread) tasks are allowed to be queued for | |
75 // execution. | |
76 void SetCheapTasksAllowed(bool allowed); | |
reveman
2013/02/13 22:17:36
would it be possible to leave this in the tile man
| |
77 | |
67 protected: | 78 protected: |
68 class Worker : public base::Thread { | 79 class Worker : public base::Thread { |
69 public: | 80 public: |
70 Worker(WorkerPool* worker_pool, const std::string name); | 81 Worker(WorkerPool* worker_pool, const std::string name); |
71 virtual ~Worker(); | 82 virtual ~Worker(); |
72 | 83 |
73 // This must be called before the destructor. | 84 // This must be called before the destructor. |
74 void StopAfterCompletingAllPendingTasks(); | 85 void StopAfterCompletingAllPendingTasks(); |
75 | 86 |
76 // Posts a task to the worker thread. | 87 // Posts a task to the worker thread. |
(...skipping 19 matching lines...) Expand all Loading... | |
96 WorkerPool* worker_pool_; | 107 WorkerPool* worker_pool_; |
97 base::WeakPtrFactory<Worker> weak_ptr_factory_; | 108 base::WeakPtrFactory<Worker> weak_ptr_factory_; |
98 ScopedPtrDeque<internal::WorkerPoolTask> pending_tasks_; | 109 ScopedPtrDeque<internal::WorkerPoolTask> pending_tasks_; |
99 scoped_ptr<RenderingStats> rendering_stats_; | 110 scoped_ptr<RenderingStats> rendering_stats_; |
100 bool record_rendering_stats_; | 111 bool record_rendering_stats_; |
101 }; | 112 }; |
102 | 113 |
103 explicit WorkerPool(size_t num_threads); | 114 explicit WorkerPool(size_t num_threads); |
104 | 115 |
105 WorkerPool::Worker* GetWorkerForNextTask(); | 116 WorkerPool::Worker* GetWorkerForNextTask(); |
117 bool CanPostCheapTask() const; | |
118 void PostCheapTask(scoped_ptr<internal::WorkerPoolTask> task); | |
106 | 119 |
107 private: | 120 private: |
108 class NumPendingTasksComparator { | 121 class NumPendingTasksComparator { |
109 public: | 122 public: |
110 bool operator() (const Worker* a, const Worker* b) const { | 123 bool operator() (const Worker* a, const Worker* b) const { |
111 return a->num_pending_tasks() < b->num_pending_tasks(); | 124 return a->num_pending_tasks() < b->num_pending_tasks(); |
112 } | 125 } |
113 }; | 126 }; |
114 | 127 |
115 void DidNumPendingTasksChange(); | 128 void DidNumPendingTasksChange(); |
116 void SortWorkersIfNeeded(); | 129 void SortWorkersIfNeeded(); |
117 | 130 |
118 typedef std::vector<Worker*> WorkerVector; | 131 typedef std::vector<Worker*> WorkerVector; |
119 WorkerVector workers_; | 132 WorkerVector workers_; |
120 bool workers_need_sorting_; | 133 bool workers_need_sorting_; |
121 bool shutdown_; | 134 bool shutdown_; |
122 | 135 |
136 bool cheap_tasks_allowed_; | |
137 bool running_cheap_tasks_; | |
138 ScopedPtrDeque<internal::WorkerPoolTask> pending_cheap_tasks_; | |
139 scoped_ptr<RenderingStats> cheap_rendering_stats_; | |
140 | |
123 DISALLOW_COPY_AND_ASSIGN(WorkerPool); | 141 DISALLOW_COPY_AND_ASSIGN(WorkerPool); |
124 }; | 142 }; |
125 | 143 |
126 } // namespace cc | 144 } // namespace cc |
127 | 145 |
128 #endif // CC_WORKER_POOL_H_ | 146 #endif // CC_WORKER_POOL_H_ |
OLD | NEW |