| Index: trunk/src/cc/base/worker_pool.h
|
| ===================================================================
|
| --- trunk/src/cc/base/worker_pool.h (revision 202735)
|
| +++ trunk/src/cc/base/worker_pool.h (working copy)
|
| @@ -5,52 +5,31 @@
|
| #ifndef CC_BASE_WORKER_POOL_H_
|
| #define CC_BASE_WORKER_POOL_H_
|
|
|
| -#include <deque>
|
| #include <string>
|
| -#include <vector>
|
|
|
| #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 CC_EXPORT WorkerPoolTask
|
| - : public base::RefCountedThreadSafe<WorkerPoolTask> {
|
| +class WorkerPoolTask {
|
| public:
|
| - typedef std::vector<scoped_refptr<WorkerPoolTask> > TaskVector;
|
| + virtual ~WorkerPoolTask();
|
|
|
| virtual void RunOnThread(unsigned thread_index) = 0;
|
| - virtual void DispatchCompletionCallback() = 0;
|
|
|
| - void DidSchedule();
|
| - void WillRun();
|
| - void DidRun();
|
| void DidComplete();
|
|
|
| - bool IsReadyToRun() const;
|
| - bool HasFinishedRunning() const;
|
| - bool HasCompleted() const;
|
| -
|
| - TaskVector& dependencies() { return dependencies_; }
|
| -
|
| protected:
|
| - friend class base::RefCountedThreadSafe<WorkerPoolTask>;
|
| + explicit WorkerPoolTask(const base::Closure& reply);
|
|
|
| - WorkerPoolTask();
|
| - explicit WorkerPoolTask(TaskVector* dependencies);
|
| - virtual ~WorkerPoolTask();
|
| -
|
| - private:
|
| - bool did_schedule_;
|
| - bool did_run_;
|
| - bool did_complete_;
|
| - TaskVector dependencies_;
|
| + const base::Closure reply_;
|
| };
|
|
|
| } // namespace internal
|
| @@ -63,49 +42,67 @@
|
| virtual ~WorkerPoolClient() {}
|
| };
|
|
|
| -// A worker thread pool that runs tasks provided by task graph and
|
| -// guarantees completion of all pending tasks at shutdown.
|
| +// A worker thread pool that runs rendering tasks and guarantees completion
|
| +// of all pending tasks at shutdown.
|
| class CC_EXPORT WorkerPool {
|
| public:
|
| + typedef base::Callback<void()> Callback;
|
| +
|
| virtual ~WorkerPool();
|
|
|
| + static scoped_ptr<WorkerPool> Create(
|
| + size_t num_threads,
|
| + base::TimeDelta check_for_completed_tasks_delay,
|
| + const std::string& thread_name_prefix) {
|
| + return make_scoped_ptr(new WorkerPool(num_threads,
|
| + check_for_completed_tasks_delay,
|
| + thread_name_prefix));
|
| + }
|
| +
|
| // Tells the worker pool to shutdown and returns once all pending tasks have
|
| // completed.
|
| - virtual void Shutdown();
|
| + 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);
|
| +
|
| // Set a new client.
|
| void SetClient(WorkerPoolClient* client) {
|
| client_ = client;
|
| }
|
|
|
| - // Force a check for completed tasks.
|
| - void CheckForCompletedTasks();
|
| -
|
| protected:
|
| WorkerPool(size_t num_threads,
|
| base::TimeDelta check_for_completed_tasks_delay,
|
| const std::string& thread_name_prefix);
|
|
|
| - void ScheduleTasks(internal::WorkerPoolTask* root);
|
| + void PostTask(scoped_ptr<internal::WorkerPoolTask> task);
|
|
|
| private:
|
| class Inner;
|
| friend class Inner;
|
|
|
| - typedef std::deque<scoped_refptr<internal::WorkerPoolTask> > TaskDeque;
|
| -
|
| - void OnIdle(TaskDeque* completed_tasks);
|
| + void OnTaskCompleted();
|
| + void OnIdle();
|
| void ScheduleCheckForCompletedTasks();
|
| - void DispatchCompletionCallbacks(TaskDeque* completed_tasks);
|
| + void CheckForCompletedTasks();
|
| + void DispatchCompletionCallbacks();
|
|
|
| WorkerPoolClient* client_;
|
| scoped_refptr<base::MessageLoopProxy> origin_loop_;
|
| - base::CancelableClosure check_for_completed_tasks_callback_;
|
| + base::WeakPtrFactory<WorkerPool> weak_ptr_factory_;
|
| 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
|
|
|