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