Index: cc/base/worker_pool.h |
diff --git a/cc/base/worker_pool.h b/cc/base/worker_pool.h |
index 8e14824024446eb74b148c90ec3b86812c727b9a..4bba3cf1218c030b277465ffcc1dd20391ec5254 100644 |
--- a/cc/base/worker_pool.h |
+++ b/cc/base/worker_pool.h |
@@ -5,31 +5,43 @@ |
#ifndef CC_BASE_WORKER_POOL_H_ |
#define CC_BASE_WORKER_POOL_H_ |
+#include <deque> |
#include <string> |
#include "base/cancelable_callback.h" |
+#include "base/memory/ref_counted.h" |
#include "base/memory/scoped_ptr.h" |
#include "base/memory/weak_ptr.h" |
#include "base/message_loop.h" |
#include "cc/base/cc_export.h" |
-#include "cc/base/scoped_ptr_deque.h" |
namespace cc { |
namespace internal { |
-class WorkerPoolTask { |
+class WorkerPoolTask : public base::RefCountedThreadSafe<WorkerPoolTask> { |
public: |
- virtual ~WorkerPoolTask(); |
- |
virtual void RunOnThread(unsigned thread_index) = 0; |
- |
- void DidComplete(); |
+ virtual void DispatchCompletionCallback() = 0; |
protected: |
- explicit WorkerPoolTask(const base::Closure& reply); |
+ friend class base::RefCountedThreadSafe<WorkerPoolTask>; |
+ |
+ WorkerPoolTask() {} |
+ virtual ~WorkerPoolTask() {} |
+}; |
+ |
+class WorkerPoolTaskGraph { |
+ public: |
+ virtual ~WorkerPoolTaskGraph() {} |
+ |
+ virtual bool HasMoreTasks() = 0; |
+ virtual bool HasTask(WorkerPoolTask* task) = 0; |
+ virtual WorkerPoolTask* TopTask() = 0; |
+ virtual scoped_refptr<WorkerPoolTask> TakeTask(WorkerPoolTask* task) = 0; |
- const base::Closure reply_; |
+ protected: |
+ WorkerPoolTaskGraph() {} |
}; |
} // namespace internal |
@@ -42,65 +54,43 @@ class CC_EXPORT WorkerPoolClient { |
virtual ~WorkerPoolClient() {} |
}; |
-// A worker thread pool that runs rendering tasks and guarantees completion |
-// of all pending tasks at shutdown. |
+// A worker thread pool that runs tasks provided by task graph and |
+// guarantees completion of all pending tasks at shutdown. |
class WorkerPool { |
public: |
- typedef base::Callback<void()> Callback; |
- |
virtual ~WorkerPool(); |
- static scoped_ptr<WorkerPool> Create( |
- WorkerPoolClient* client, |
- size_t num_threads, |
- base::TimeDelta check_for_completed_tasks_delay, |
- const std::string& thread_name_prefix) { |
- return make_scoped_ptr(new WorkerPool(client, |
- num_threads, |
- check_for_completed_tasks_delay, |
- thread_name_prefix)); |
- } |
- |
// Tells the worker pool to shutdown and returns once all pending tasks have |
// completed. |
void Shutdown(); |
- // 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); |
- |
protected: |
WorkerPool(WorkerPoolClient* client, |
size_t num_threads, |
base::TimeDelta check_for_completed_tasks_delay, |
const std::string& thread_name_prefix); |
- void PostTask(scoped_ptr<internal::WorkerPoolTask> task); |
+ void ScheduleTasks(scoped_ptr<internal::WorkerPoolTaskGraph> task_graph); |
private: |
class Inner; |
friend class Inner; |
- void OnTaskCompleted(); |
- void OnIdle(); |
+ typedef std::deque<scoped_refptr<internal::WorkerPoolTask> > TaskDeque; |
+ |
+ void OnIdle(TaskDeque* completed_tasks); |
void ScheduleCheckForCompletedTasks(); |
void CheckForCompletedTasks(); |
- void DispatchCompletionCallbacks(); |
+ void DispatchCompletionCallbacks(TaskDeque* completed_tasks); |
WorkerPoolClient* client_; |
scoped_refptr<base::MessageLoopProxy> origin_loop_; |
- base::WeakPtrFactory<WorkerPool> weak_ptr_factory_; |
+ base::CancelableClosure check_for_completed_tasks_callback_; |
base::TimeDelta check_for_completed_tasks_delay_; |
bool check_for_completed_tasks_pending_; |
- // Holds all completed tasks for which we have not yet dispatched |
- // reply callbacks. |
- ScopedPtrDeque<internal::WorkerPoolTask> completed_tasks_; |
- |
// Hide the gory details of the worker pool in |inner_|. |
const scoped_ptr<Inner> inner_; |
- |
- DISALLOW_COPY_AND_ASSIGN(WorkerPool); |
}; |
} // namespace cc |