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

Unified Diff: cc/raster/task.h

Issue 1903733003: cc: Implement states for Task for stricter control. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@land_merge_tile_task_runner
Patch Set: nits Created 4 years, 8 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
Index: cc/raster/task.h
diff --git a/cc/raster/task.h b/cc/raster/task.h
index 96959c1ba00b0e4bf8a0e3044e698ee84bfafd8e..faa14897ff75be904e08b412d600d35656635aef 100644
--- a/cc/raster/task.h
+++ b/cc/raster/task.h
@@ -13,6 +13,39 @@
#include "cc/base/cc_export.h"
namespace cc {
+class Task;
+
+// States to manage life cycle of a task. Task gets created with NEW state and
+// concludes either in FINISHED or CANCELLED state. So possible life cycle
+// paths for task are -
+// NEW -> SCHEDULED -> RUNNING -> FINISHED
+// NEW -> SCHEDULED -> CANCELED
+class CC_EXPORT TaskState {
+ public:
+ bool IsScheduled() const;
+ bool IsRunning() const;
+ bool IsFinished() const;
+ bool IsCanceled() const;
+
+ // Functions to change the state of task. These functions should be called
+ // only from TaskGraphWorkQueue where the life cycle of a task is decided or
+ // from tests. These functions are not thread-safe. Caller is responsible for
+ // thread safety.
+ void Reset(); // Sets state to NEW.
+ void DidSchedule();
+ void DidStart();
+ void DidFinish();
+ void DidCancel();
+
+ private:
+ friend class Task;
+
+ // Let only Task class create the TaskState.
+ TaskState();
+ ~TaskState();
+
+ enum { NEW, SCHEDULED, RUNNING, FINISHED, CANCELED } value_;
ericrk 2016/04/21 18:24:25 please use an "enum class" for extra safety.
prashant.n 2016/04/22 03:57:56 I thought using simple enum as it is private. I'l
+};
// A task which can be run by a TaskGraphRunner. To run a Task, it should be
// inserted into a TaskGraph, which can then be scheduled on the
@@ -21,23 +54,21 @@ class CC_EXPORT Task : public base::RefCountedThreadSafe<Task> {
public:
typedef std::vector<scoped_refptr<Task>> Vector;
+ TaskState& state() { return state_; }
+
// Subclasses should implement this method. RunOnWorkerThread may be called
// on any thread, and subclasses are responsible for locking and thread
// safety.
virtual void RunOnWorkerThread() = 0;
- void WillRun();
- void DidRun();
- bool HasFinishedRunning() const;
-
protected:
friend class base::RefCountedThreadSafe<Task>;
Task();
virtual ~Task();
- bool will_run_;
- bool did_run_;
+ private:
+ TaskState state_;
};
// A task dependency graph describes the order in which to execute a set
« no previous file with comments | « cc/raster/synchronous_task_graph_runner.cc ('k') | cc/raster/task.cc » ('j') | cc/raster/task.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698