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

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: feedback 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
« no previous file with comments | « cc/raster/synchronous_task_graph_runner.cc ('k') | cc/raster/task.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/raster/task.h
diff --git a/cc/raster/task.h b/cc/raster/task.h
index 96959c1ba00b0e4bf8a0e3044e698ee84bfafd8e..54bcf8b6b1a508b9d31e50fa39e0a327f144513c 100644
--- a/cc/raster/task.h
+++ b/cc/raster/task.h
@@ -13,6 +13,41 @@
#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 class Value : uint16_t { NEW, SCHEDULED, RUNNING, FINISHED, CANCELED };
+
+ Value value_;
+};
// 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 +56,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') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698