| Index: cc/base/worker_pool.h
|
| diff --git a/cc/base/worker_pool.h b/cc/base/worker_pool.h
|
| index aa49ec9f9bfcf18fc208ab24dcf2201ef4c9e0c6..a27757a1f7c03b177d56051226c22340eecd012d 100644
|
| --- a/cc/base/worker_pool.h
|
| +++ b/cc/base/worker_pool.h
|
| @@ -5,31 +5,52 @@
|
| #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 WorkerPoolTask {
|
| +class CC_EXPORT WorkerPoolTask
|
| + : public base::RefCountedThreadSafe<WorkerPoolTask> {
|
| public:
|
| - virtual ~WorkerPoolTask();
|
| + typedef std::vector<scoped_refptr<WorkerPoolTask> > TaskVector;
|
|
|
| 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:
|
| - explicit WorkerPoolTask(const base::Closure& reply);
|
| + friend class base::RefCountedThreadSafe<WorkerPoolTask>;
|
| +
|
| + WorkerPoolTask();
|
| + explicit WorkerPoolTask(TaskVector* dependencies);
|
| + virtual ~WorkerPoolTask();
|
|
|
| - const base::Closure reply_;
|
| + private:
|
| + bool did_schedule_;
|
| + bool did_run_;
|
| + bool did_complete_;
|
| + TaskVector dependencies_;
|
| };
|
|
|
| } // namespace internal
|
| @@ -42,67 +63,50 @@ 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 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.
|
| - 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);
|
| + virtual void Shutdown();
|
|
|
| // 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 PostTask(scoped_ptr<internal::WorkerPoolTask> task);
|
| + void ScheduleTasks(internal::WorkerPoolTask* root);
|
|
|
| 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_;
|
| + bool in_dispatch_completion_callbacks_;
|
|
|
| // Hide the gory details of the worker pool in |inner_|.
|
| const scoped_ptr<Inner> inner_;
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(WorkerPool);
|
| };
|
|
|
| } // namespace cc
|
|
|