Chromium Code Reviews| Index: cc/worker_pool.h |
| diff --git a/cc/worker_pool.h b/cc/worker_pool.h |
| index f47dd70b9981b23af18184c6c3f0ea911b051c12..d6e91587ae51a00bda5a10a0dc8ad653a701dab0 100644 |
| --- a/cc/worker_pool.h |
| +++ b/cc/worker_pool.h |
| @@ -9,6 +9,7 @@ |
| #include "base/basictypes.h" |
| #include "base/callback.h" |
| +#include "base/cancelable_callback.h" |
| #include "base/memory/scoped_ptr.h" |
| #include "base/memory/weak_ptr.h" |
| #include "base/threading/thread.h" |
| @@ -24,12 +25,16 @@ class WorkerPoolTask { |
| virtual void Run(RenderingStats* rendering_stats) = 0; |
| - void Completed(); |
| + bool IsPending(); |
|
nduca
2013/02/13 08:29:32
Can you say HasCompleted? So we dont mix completed
reveman
2013/02/13 08:46:38
Done.
|
| + void Completed(bool more_tasks_completed); |
| protected: |
| - WorkerPoolTask(const base::Closure& reply); |
| + WorkerPoolTask(const base::Callback<void(bool)>& reply); |
| - base::Closure reply_; |
| + base::Callback<void(bool)> reply_; |
| + |
| + // Accessed from multiple threads. Set to 1 when task has completed. |
| + base::subtle::Atomic32 completed_; |
| }; |
| } // namespace internal |
| @@ -39,6 +44,7 @@ class WorkerPoolTask { |
| class WorkerPool { |
| public: |
| typedef base::Callback<void(RenderingStats*)> Callback; |
| + typedef base::Callback<void(bool)> Reply; |
| virtual ~WorkerPool(); |
| @@ -52,11 +58,7 @@ class WorkerPool { |
| // Posts |task| to worker pool. On completion, |reply| |
| // 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. |
|
nduca
2013/02/13 08:29:32
I wonder, can you shift the raster throttle stuff
reveman
2013/02/13 08:46:38
my current throttle values are derived from the kM
|
| - bool IsBusy(); |
| + void PostTaskAndReply(const Callback& task, const Reply& reply); |
| // Toggle rendering stats collection. |
| void SetRecordRenderingStats(bool record_rendering_stats); |
| @@ -76,6 +78,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,12 +94,13 @@ 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_; |
| @@ -112,13 +118,43 @@ class WorkerPool { |
| } |
| }; |
| - void DidNumPendingTasksChange(); |
| + // Schedule a completed tasks check if not already pending. |
| + void ScheduleCheckForCompletedTasks(); |
| + |
| + // Called on origin thread before posting task to worker. |
| + void WillPostWorkTask(); |
| + |
| + // Called on worker thread after completing work. |
| + void OnWorkCompletedOnWorkerThread(); |
| + |
| + // Called on origin thread after becoming idle. |
| + void OnIdle(); |
| + |
| + // Check for completed tasks and run reply callbacks. |
| + void CheckForCompletedTasks(); |
| + |
| + // Called when processing task completion. |
| + void OnTaskCompleted(); |
| + |
| + // Returns true when work has completed in worker thread but |
| + // task completion has not yet been processed. |
| + bool MoreTasksCompleted(); |
| + |
| + // Ensure workers are sorted by number of pending tasks. |
| void SortWorkersIfNeeded(); |
| typedef std::vector<Worker*> WorkerVector; |
| WorkerVector workers_; |
| + scoped_refptr<base::MessageLoopProxy> origin_loop_; |
| + base::WeakPtrFactory<WorkerPool> weak_ptr_factory_; |
| bool workers_need_sorting_; |
| + int task_count_; |
| bool shutdown_; |
| + base::CancelableClosure check_for_completed_tasks_callback_; |
| + bool check_for_completed_tasks_pending_; |
| + base::Closure idle_callback_; |
| + // Accessed from multiple threads. 0 when worker pool is idle. |
| + base::subtle::Atomic32 work_count_; |
|
nduca
2013/02/13 08:29:32
better name
|
| DISALLOW_COPY_AND_ASSIGN(WorkerPool); |
| }; |