1 /* 2 * Copyright (c) 2021 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 #ifndef ECMASCRIPT_TASKPOOL_TASK_H 17 #define ECMASCRIPT_TASKPOOL_TASK_H 18 19 #include "libpandabase/macros.h" 20 21 namespace panda::ecmascript { 22 enum class TaskType : uint8_t { 23 PGO_SAVE_TASK, 24 PGO_RESET_OUT_PATH_TASK, 25 PGO_DUMP_TASK, 26 ALL, 27 }; 28 29 static constexpr int32_t ALL_TASK_ID = -1; 30 // Tasks not managed by VM 31 static constexpr int32_t GLOBAL_TASK_ID = 0; 32 33 class Task { 34 public: Task(int32_t id)35 explicit Task(int32_t id) : id_(id) {}; 36 virtual ~Task() = default; 37 virtual bool Run(uint32_t threadIndex) = 0; 38 39 NO_COPY_SEMANTIC(Task); 40 NO_MOVE_SEMANTIC(Task); 41 GetTaskType()42 virtual TaskType GetTaskType() const 43 { 44 return TaskType::ALL; 45 } 46 GetId()47 int32_t GetId() const 48 { 49 return id_; 50 } 51 Terminated()52 void Terminated() 53 { 54 terminate_ = true; 55 } 56 IsTerminate()57 bool IsTerminate() const 58 { 59 return terminate_; 60 } 61 62 private: 63 int32_t id_ {0}; 64 volatile bool terminate_ {false}; 65 }; 66 } // namespace panda::ecmascript 67 #endif // ECMASCRIPT_TASKPOOL_TASK_H 68