• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "libpandabase/taskmanager/task.h"
17 
18 namespace panda::taskmanager {
19 
Task(TaskProperties properties,RunnerCallback runner)20 Task::Task(TaskProperties properties, RunnerCallback runner) : properties_(properties), runner_(std::move(runner)) {}
21 
22 /* static */
Create(TaskProperties properties,RunnerCallback runner)23 Task Task::Create(TaskProperties properties, RunnerCallback runner)
24 {
25     Task task(properties, std::move(runner));
26     return task;
27 }
28 
GetTaskProperties() const29 TaskProperties Task::GetTaskProperties() const
30 {
31     return properties_;
32 }
33 
RunTask()34 void Task::RunTask()
35 {
36     runner_();
37 }
38 
operator <<(std::ostream & os,TaskType type)39 std::ostream &operator<<(std::ostream &os, TaskType type)
40 {
41     switch (type) {
42         case TaskType::GC:
43             os << "TaskType::GC";
44             break;
45         case TaskType::JIT:
46             os << "TaskType::JIT";
47             break;
48         default:
49             UNREACHABLE();
50             break;
51     }
52     return os;
53 }
54 
operator <<(std::ostream & os,VMType type)55 std::ostream &operator<<(std::ostream &os, VMType type)
56 {
57     switch (type) {
58         case VMType::DYNAMIC_VM:
59             os << "VMType::DYNAMIC_VM";
60             break;
61         case VMType::STATIC_VM:
62             os << "VMType::STATIC_VM";
63             break;
64         default:
65             UNREACHABLE();
66             break;
67     }
68     return os;
69 }
70 
operator <<(std::ostream & os,TaskExecutionMode mode)71 std::ostream &operator<<(std::ostream &os, TaskExecutionMode mode)
72 {
73     switch (mode) {
74         case TaskExecutionMode::FOREGROUND:
75             os << "TaskExecutionMode::FOREGROUND";
76             break;
77         case TaskExecutionMode::BACKGROUND:
78             os << "TaskExecutionMode::BACKGROUND";
79             break;
80         default:
81             UNREACHABLE();
82             break;
83     }
84     return os;
85 }
86 
operator <<(std::ostream & os,TaskProperties prop)87 std::ostream &operator<<(std::ostream &os, TaskProperties prop)
88 {
89     os << "{" << prop.GetTaskType() << "," << prop.GetVMType() << "," << prop.GetTaskExecutionMode() << "}";
90     return os;
91 }
92 
93 }  // namespace panda::taskmanager
94