Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(360)

Unified Diff: trunk/src/cc/base/worker_pool.h

Issue 16178002: Revert 202363 "cc: Cancel and re-prioritize worker pool tasks." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « trunk/src/cc/base/scoped_ptr_hash_map.h ('k') | trunk/src/cc/base/worker_pool.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « trunk/src/cc/base/scoped_ptr_hash_map.h ('k') | trunk/src/cc/base/worker_pool.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698