Chromium Code Reviews| Index: cc/worker_pool.h |
| diff --git a/cc/worker_pool.h b/cc/worker_pool.h |
| index f47dd70b9981b23af18184c6c3f0ea911b051c12..9cdb223751ad13e0f70cf0702be0160ce3aae771 100644 |
| --- a/cc/worker_pool.h |
| +++ b/cc/worker_pool.h |
| @@ -24,16 +24,28 @@ class WorkerPoolTask { |
| virtual void Run(RenderingStats* rendering_stats) = 0; |
| + bool IsPending(); |
| void Completed(); |
| protected: |
| WorkerPoolTask(const base::Closure& reply); |
| base::Closure reply_; |
| + |
| + // Accessed from multiple threads. Set to 1 when task has completed. |
| + base::subtle::Atomic32 completed_; |
| }; |
| } // namespace internal |
| +class WorkerPoolClient { |
| + public: |
| + virtual void OnIdle() = 0; |
|
brianderson
2013/02/13 01:19:57
Can we rename this to OnWorkerPoolIdle?
reveman
2013/02/13 08:12:51
Latest patch doesn't need this client interface.
|
| + |
| + protected: |
| + virtual ~WorkerPoolClient() {} |
| +}; |
| + |
| // A worker thread pool that runs rendering tasks and guarantees completion |
| // of all pending tasks at shutdown. |
| class WorkerPool { |
| @@ -42,8 +54,9 @@ class WorkerPool { |
| virtual ~WorkerPool(); |
| - static scoped_ptr<WorkerPool> Create(size_t num_threads) { |
| - return make_scoped_ptr(new WorkerPool(num_threads)); |
| + static scoped_ptr<WorkerPool> Create( |
| + WorkerPoolClient* client, size_t num_threads) { |
| + return make_scoped_ptr(new WorkerPool(client, num_threads)); |
| } |
| // Tells the worker pool to shutdown and returns once all pending tasks have |
| @@ -54,9 +67,8 @@ class WorkerPool { |
| // is posted to the thread that called PostTaskAndReply(). |
| void PostTaskAndReply(const Callback& task, const base::Closure& reply); |
| - // Returns true when worker pool has reached its internal limit for number |
| - // of pending tasks. |
| - bool IsBusy(); |
| + // Check for completed tasks and run reply callbacks. |
| + void CheckForCompletedTasks(); |
| // Toggle rendering stats collection. |
| void SetRecordRenderingStats(bool record_rendering_stats); |
| @@ -76,6 +88,9 @@ class WorkerPool { |
| // Posts a task to the worker thread. |
| void PostTask(scoped_ptr<internal::WorkerPoolTask> task); |
| + // Check for completed tasks and run reply callbacks. |
| + void CheckForCompletedTasks(); |
| + |
| int num_pending_tasks() const { return pending_tasks_.size(); } |
| void set_record_rendering_stats(bool record_rendering_stats) { |
| record_rendering_stats_ = record_rendering_stats; |
| @@ -89,18 +104,19 @@ class WorkerPool { |
| private: |
| static void RunTask( |
| - internal::WorkerPoolTask* task, RenderingStats* rendering_stats); |
| + internal::WorkerPoolTask* task, |
| + WorkerPool* worker_pool, |
| + RenderingStats* rendering_stats); |
| void OnTaskCompleted(); |
| WorkerPool* worker_pool_; |
| - base::WeakPtrFactory<Worker> weak_ptr_factory_; |
| ScopedPtrDeque<internal::WorkerPoolTask> pending_tasks_; |
| scoped_ptr<RenderingStats> rendering_stats_; |
| bool record_rendering_stats_; |
| }; |
| - explicit WorkerPool(size_t num_threads); |
| + WorkerPool(WorkerPoolClient* client, size_t num_threads); |
| WorkerPool::Worker* GetWorkerForNextTask(); |
| @@ -112,13 +128,26 @@ class WorkerPool { |
| } |
| }; |
| + // Called on origin thread before posting task to worker. |
| + void WillPostMoreWork(); |
| + // Called on worker thread after completing work. |
| + void OnWorkCompleted(); |
| + // Called on origin thread after becoming idle. |
| + void OnIdle(); |
| + |
| void DidNumPendingTasksChange(); |
| void SortWorkersIfNeeded(); |
| typedef std::vector<Worker*> WorkerVector; |
| WorkerVector workers_; |
| + WorkerPoolClient* client_; |
| + scoped_refptr<base::MessageLoopProxy> origin_loop_; |
| + base::WeakPtrFactory<WorkerPool> weak_ptr_factory_; |
| bool workers_need_sorting_; |
| bool shutdown_; |
| + base::Closure idle_handler_; |
| + // Accessed from multiple threads. 0 when worker pool is idle. |
| + base::subtle::Atomic32 work_count_; |
| DISALLOW_COPY_AND_ASSIGN(WorkerPool); |
| }; |