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 ALL, 26 }; 27 28 static constexpr int32_t ALL_TASK_ID = -1; 29 // Tasks not managed by VM 30 static constexpr int32_t GLOBAL_TASK_ID = 0; 31 32 class Task { 33 public: Task(int32_t id)34 explicit Task(int32_t id) : id_(id) {}; 35 virtual ~Task() = default; 36 virtual bool Run(uint32_t threadIndex) = 0; 37 38 NO_COPY_SEMANTIC(Task); 39 NO_MOVE_SEMANTIC(Task); 40 GetTaskType() const41 virtual TaskType GetTaskType() const 42 { 43 return TaskType::ALL; 44 } 45 GetId() const46 int32_t GetId() const 47 { 48 return id_; 49 } 50 Terminated()51 void Terminated() 52 { 53 terminate_ = true; 54 } 55 IsTerminate() const56 bool IsTerminate() const 57 { 58 return terminate_; 59 } 60 61 private: 62 int32_t id_ {0}; 63 volatile bool terminate_ {false}; 64 }; 65 } // namespace panda::ecmascript 66 #endif // ECMASCRIPT_TASKPOOL_TASK_H 67