OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CC_RASTER_TASK_H_ | 5 #ifndef CC_RASTER_TASK_H_ |
6 #define CC_RASTER_TASK_H_ | 6 #define CC_RASTER_TASK_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "cc/base/cc_export.h" | 13 #include "cc/base/cc_export.h" |
14 | 14 |
15 namespace cc { | 15 namespace cc { |
16 class Task; | |
17 | |
18 // States to manage life cycle of a task. Task gets created with NEW state and | |
19 // concludes either in FINISHED or CANCELLED state. So possible life cycle | |
20 // paths for task are - | |
21 // NEW -> SCHEDULED -> RUNNING -> FINISHED | |
22 // NEW -> SCHEDULED -> CANCELED | |
23 class CC_EXPORT TaskState { | |
24 public: | |
25 bool IsScheduled() const; | |
26 bool IsRunning() const; | |
27 bool IsFinished() const; | |
28 bool IsCanceled() const; | |
29 | |
30 // Functions to change the state of task. These functions should be called | |
31 // only from TaskGraphWorkQueue where the life cycle of a task is decided or | |
32 // from tests. These functions are not thread-safe. Caller is responsible for | |
33 // thread safety. | |
34 void Reset(); // Sets state to NEW. | |
35 void DidSchedule(); | |
36 void DidStart(); | |
37 void DidFinish(); | |
38 void DidCancel(); | |
39 | |
40 private: | |
41 friend class Task; | |
42 | |
43 // Let only Task class create the TaskState. | |
44 TaskState(); | |
45 ~TaskState(); | |
46 | |
47 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
| |
48 }; | |
16 | 49 |
17 // A task which can be run by a TaskGraphRunner. To run a Task, it should be | 50 // A task which can be run by a TaskGraphRunner. To run a Task, it should be |
18 // inserted into a TaskGraph, which can then be scheduled on the | 51 // inserted into a TaskGraph, which can then be scheduled on the |
19 // TaskGraphRunner. | 52 // TaskGraphRunner. |
20 class CC_EXPORT Task : public base::RefCountedThreadSafe<Task> { | 53 class CC_EXPORT Task : public base::RefCountedThreadSafe<Task> { |
21 public: | 54 public: |
22 typedef std::vector<scoped_refptr<Task>> Vector; | 55 typedef std::vector<scoped_refptr<Task>> Vector; |
23 | 56 |
57 TaskState& state() { return state_; } | |
58 | |
24 // Subclasses should implement this method. RunOnWorkerThread may be called | 59 // Subclasses should implement this method. RunOnWorkerThread may be called |
25 // on any thread, and subclasses are responsible for locking and thread | 60 // on any thread, and subclasses are responsible for locking and thread |
26 // safety. | 61 // safety. |
27 virtual void RunOnWorkerThread() = 0; | 62 virtual void RunOnWorkerThread() = 0; |
28 | 63 |
29 void WillRun(); | |
30 void DidRun(); | |
31 bool HasFinishedRunning() const; | |
32 | |
33 protected: | 64 protected: |
34 friend class base::RefCountedThreadSafe<Task>; | 65 friend class base::RefCountedThreadSafe<Task>; |
35 | 66 |
36 Task(); | 67 Task(); |
37 virtual ~Task(); | 68 virtual ~Task(); |
38 | 69 |
39 bool will_run_; | 70 private: |
40 bool did_run_; | 71 TaskState state_; |
41 }; | 72 }; |
42 | 73 |
43 // A task dependency graph describes the order in which to execute a set | 74 // A task dependency graph describes the order in which to execute a set |
44 // of tasks. Dependencies are represented as edges. Each node is assigned | 75 // of tasks. Dependencies are represented as edges. Each node is assigned |
45 // a category, a priority and a run count that matches the number of | 76 // a category, a priority and a run count that matches the number of |
46 // dependencies. Priority range from 0 (most favorable scheduling) to UINT16_MAX | 77 // dependencies. Priority range from 0 (most favorable scheduling) to UINT16_MAX |
47 // (least favorable). Categories range from 0 to UINT16_MAX. It is up to the | 78 // (least favorable). Categories range from 0 to UINT16_MAX. It is up to the |
48 // implementation and its consumer to determine the meaning (if any) of a | 79 // implementation and its consumer to determine the meaning (if any) of a |
49 // category. A TaskGraphRunner implementation may chose to prioritize certain | 80 // category. A TaskGraphRunner implementation may chose to prioritize certain |
50 // categories over others, regardless of the individual priorities of tasks. | 81 // categories over others, regardless of the individual priorities of tasks. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
84 void Swap(TaskGraph* other); | 115 void Swap(TaskGraph* other); |
85 void Reset(); | 116 void Reset(); |
86 | 117 |
87 Node::Vector nodes; | 118 Node::Vector nodes; |
88 Edge::Vector edges; | 119 Edge::Vector edges; |
89 }; | 120 }; |
90 | 121 |
91 } // namespace cc | 122 } // namespace cc |
92 | 123 |
93 #endif // CC_RASTER_TASK_H_ | 124 #endif // CC_RASTER_TASK_H_ |
OLD | NEW |