forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask.cc
98 lines (74 loc) · 2.29 KB
/
task.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "cc/raster/task.h"
#include "base/logging.h"
namespace cc {
TaskState::TaskState() : value_(Value::NEW) {}
TaskState::~TaskState() {
DCHECK(value_ != Value::RUNNING)
<< "Running task should never get destroyed.";
DCHECK(value_ == Value::FINISHED || value_ == Value::CANCELED)
<< "Task, if scheduled, should get concluded either in FINISHED or "
"CANCELED state.";
}
bool TaskState::IsScheduled() const {
return value_ == Value::SCHEDULED;
}
bool TaskState::IsRunning() const {
return value_ == Value::RUNNING;
}
bool TaskState::IsFinished() const {
return value_ == Value::FINISHED;
}
bool TaskState::IsCanceled() const {
return value_ == Value::CANCELED;
}
void TaskState::Reset() {
value_ = Value::NEW;
}
void TaskState::DidSchedule() {
DCHECK(value_ == Value::NEW)
<< "Task should be in NEW state to get scheduled.";
value_ = Value::SCHEDULED;
}
void TaskState::DidStart() {
DCHECK(value_ == Value::SCHEDULED)
<< "Task should be only in SCHEDULED state to start, that is it should "
"not be started or finished.";
value_ = Value::RUNNING;
}
void TaskState::DidFinish() {
DCHECK(value_ == Value::RUNNING)
<< "Task should be running and not finished earlier.";
value_ = Value::FINISHED;
}
void TaskState::DidCancel() {
DCHECK(value_ == Value::NEW || value_ == Value::SCHEDULED)
<< "Task should be either new or scheduled to get canceled.";
value_ = Value::CANCELED;
}
Task::Task() {}
Task::~Task() {}
TaskGraph::TaskGraph() {}
TaskGraph::TaskGraph(TaskGraph&& other) = default;
TaskGraph::~TaskGraph() {}
TaskGraph::Node::Node(scoped_refptr<Task> task,
uint16_t category,
uint16_t priority,
uint32_t dependencies)
: task(std::move(task)),
category(category),
priority(priority),
dependencies(dependencies) {}
TaskGraph::Node::Node(Node&& other) = default;
TaskGraph::Node::~Node() = default;
void TaskGraph::Swap(TaskGraph* other) {
nodes.swap(other->nodes);
edges.swap(other->edges);
}
void TaskGraph::Reset() {
nodes.clear();
edges.clear();
}
} // namespace cc