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

Side by Side Diff: cc/raster/task.cc

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 unified diff | Download patch
OLDNEW
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 #include "cc/raster/task.h" 5 #include "cc/raster/task.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 8
9 namespace cc { 9 namespace cc {
10 10
11 Task::Task() : will_run_(false), did_run_(false) {} 11 TaskState::TaskState() : value_(NEW) {}
12 12
13 Task::~Task() { 13 TaskState::~TaskState() {
14 DCHECK(!will_run_); 14 DCHECK_NE(value_, RUNNING) << "Running task should never get destroyed.";
15 DCHECK(value_ == NEW || value_ == FINISHED || value_ == CANCELED)
16 << "Task, if scheduled, should get concluded either in FINISHED or "
17 "CANCELED state.";
15 } 18 }
16 19
17 void Task::WillRun() { 20 bool TaskState::IsScheduled() const {
18 DCHECK(!will_run_); 21 return (value_ == SCHEDULED);
ericrk 2016/04/21 18:24:25 nit: why the extra ()?
prashant.n 2016/04/22 03:57:56 For readability I added. I guess chromium does no
19 DCHECK(!did_run_);
20 will_run_ = true;
21 } 22 }
22 23
23 void Task::DidRun() { 24 bool TaskState::IsRunning() const {
24 DCHECK(will_run_); 25 return (value_ == RUNNING);
25 will_run_ = false; 26 }
26 did_run_ = true; 27 bool TaskState::IsFinished() const {
28 return (value_ == FINISHED);
29 }
30 bool TaskState::IsCanceled() const {
31 return (value_ == CANCELED);
27 } 32 }
28 33
29 bool Task::HasFinishedRunning() const { 34 void TaskState::Reset() {
30 return did_run_; 35 value_ = NEW;
31 } 36 }
32 37
38 void TaskState::DidSchedule() {
39 DCHECK(value_ == NEW) << "Task should be in NEW state to get scheduled.";
40 value_ = SCHEDULED;
41 }
42
43 void TaskState::DidStart() {
44 DCHECK_EQ(value_, SCHEDULED) << "Task should be scheduled to start.";
45 DCHECK(value_ != RUNNING && value_ != FINISHED)
ericrk 2016/04/21 18:24:25 This check is redundant with the above. (they both
46 << "Task should not be running or finished.";
47 value_ = RUNNING;
48 }
49
50 void TaskState::DidFinish() {
51 DCHECK(value_ == RUNNING && value_ != FINISHED)
52 << "Task should be running and not finished.";
53 value_ = FINISHED;
54 }
55
56 void TaskState::DidCancel() {
57 DCHECK(value_ == NEW || (value_ == SCHEDULED && value_ != RUNNING))
ericrk 2016/04/21 18:24:25 Should read DCHECK(value_ == NEW || value_ == SCHE
58 << "Task should be scheduled and not running to get canceled.";
59 value_ = CANCELED;
60 }
61
62 Task::Task() {}
63
64 Task::~Task() {}
65
33 TaskGraph::TaskGraph() {} 66 TaskGraph::TaskGraph() {}
34 67
35 TaskGraph::TaskGraph(const TaskGraph& other) = default; 68 TaskGraph::TaskGraph(const TaskGraph& other) = default;
36 69
37 TaskGraph::~TaskGraph() {} 70 TaskGraph::~TaskGraph() {}
38 71
39 void TaskGraph::Swap(TaskGraph* other) { 72 void TaskGraph::Swap(TaskGraph* other) {
40 nodes.swap(other->nodes); 73 nodes.swap(other->nodes);
41 edges.swap(other->edges); 74 edges.swap(other->edges);
42 } 75 }
43 76
44 void TaskGraph::Reset() { 77 void TaskGraph::Reset() {
45 nodes.clear(); 78 nodes.clear();
46 edges.clear(); 79 edges.clear();
47 } 80 }
48 81
49 } // namespace cc 82 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698