diff options
author | reveman@chromium.org <reveman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-30 03:34:13 +0000 |
---|---|---|
committer | reveman@chromium.org <reveman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-30 03:34:13 +0000 |
commit | 362c9d06bc4d5b0a6760b5141125829d986cf7e5 (patch) | |
tree | 7b54bf5e810579a0bc2f5c1bc82d83cb25b6dbd4 /cc/resources/raster_worker_pool.h | |
parent | 3d82df66cceb50b8088b818e8ca74015d372872e (diff) | |
download | chromium_src-362c9d06bc4d5b0a6760b5141125829d986cf7e5.zip chromium_src-362c9d06bc4d5b0a6760b5141125829d986cf7e5.tar.gz chromium_src-362c9d06bc4d5b0a6760b5141125829d986cf7e5.tar.bz2 |
Re-land: cc: Cancel and re-prioritize worker pool tasks.
This adds a task graph interface to the worker pool and
implements a simple queue instance of this interface for
use by the tile manager.
The task graph interface can be used describe more
complicated task dependencies in the future and
provides the immediate benefit of seamlessly being
able to cancel and re-prioritize tasks.
BUG=178974,244642
TEST=cc_unittests --gtest_filter=WorkerPoolTest.Dependencies
Review URL: https://chromiumcodereview.appspot.com/14689004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@203041 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/resources/raster_worker_pool.h')
-rw-r--r-- | cc/resources/raster_worker_pool.h | 65 |
1 files changed, 59 insertions, 6 deletions
diff --git a/cc/resources/raster_worker_pool.h b/cc/resources/raster_worker_pool.h index 76d0497..98032dd 100644 --- a/cc/resources/raster_worker_pool.h +++ b/cc/resources/raster_worker_pool.h @@ -5,8 +5,6 @@ #ifndef CC_RESOURCES_RASTER_WORKER_POOL_H_ #define CC_RESOURCES_RASTER_WORKER_POOL_H_ -#include <string> - #include "cc/base/worker_pool.h" namespace cc { @@ -15,7 +13,55 @@ class PicturePileImpl; // A worker thread pool that runs raster tasks. class CC_EXPORT RasterWorkerPool : public WorkerPool { public: - typedef base::Callback<void(PicturePileImpl* picture_pile)> RasterCallback; + class Task { + public: + typedef base::Callback<void(bool)> Reply; + + // Highest priority task first. Order of execution is not guaranteed. + class Queue { + public: + Queue(); + ~Queue(); + + bool empty() const { return tasks_.empty(); } + + // Add task to the back of the queue. + void Append(const Task& task); + + private: + friend class RasterWorkerPool; + + internal::WorkerPoolTask::TaskVector tasks_; + }; + + Task(); + Task(const base::Closure& callback, const Reply& reply); + explicit Task(Queue* dependencies); + ~Task(); + + // Returns true if Task is null (doesn't refer to anything). + bool is_null() const { return !internal_; } + + // Returns the Task into an uninitialized state. + void Reset(); + + protected: + friend class RasterWorkerPool; + + explicit Task(scoped_refptr<internal::WorkerPoolTask> internal); + + scoped_refptr<internal::WorkerPoolTask> internal_; + }; + + class PictureTask : public Task { + public: + typedef base::Callback<void(PicturePileImpl*)> Callback; + + PictureTask(PicturePileImpl* picture_pile, + const Callback& callback, + const Reply& reply, + Queue* dependencies); + }; virtual ~RasterWorkerPool(); @@ -23,9 +69,16 @@ class CC_EXPORT RasterWorkerPool : public WorkerPool { return make_scoped_ptr(new RasterWorkerPool(num_threads)); } - void PostRasterTaskAndReply(PicturePileImpl* picture_pile, - const RasterCallback& task, - const base::Closure& reply); + // Tells the worker pool to shutdown after canceling all previously + // scheduled tasks. Reply callbacks are still guaranteed to run. + virtual void Shutdown() OVERRIDE; + + // Schedule running of |root| task and all its dependencies. Tasks + // previously scheduled but no longer needed to run |root| will be + // canceled unless already running. Once scheduled, reply callbacks + // are guaranteed to run for all tasks even if they later get + // canceled by another call to ScheduleTasks(). + void ScheduleTasks(Task* root); private: explicit RasterWorkerPool(size_t num_threads); |