1 /* 2 * Copyright (c) 2020-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 GRAPHIC_LITE_TASK_MANAGER_H 17 #define GRAPHIC_LITE_TASK_MANAGER_H 18 19 #include <cstdint> 20 21 #include "gfx_utils/list.h" 22 #include "common/task.h" 23 24 namespace OHOS { 25 class TaskManager : public HeapBase { 26 public: 27 /** 28 * @brief return TaskManager's singleton 29 * @return TaskManager* 30 */ 31 static TaskManager* GetInstance(); 32 33 /** 34 * @brief add task to task manager 35 * @param [in] task task pointer 36 */ 37 void Add(Task* task); 38 39 /** 40 * @brief del task from task manager 41 * @param [in] task task pointer 42 */ 43 void Remove(Task* task); 44 45 /** 46 * @brief set task run 47 * @param [in] enable task run 48 */ SetTaskRun(bool enable)49 void SetTaskRun(bool enable) 50 { 51 canTaskRun_ = enable; 52 } 53 54 /** 55 * @brief get task run 56 * @return enable task run 57 */ GetTaskRun()58 bool GetTaskRun() const 59 { 60 return canTaskRun_; 61 } 62 63 /** 64 * @brief run all task 65 */ 66 void TaskHandler(); 67 68 /** 69 * @brief reset the mutex of task handler, must be used carefully 70 */ 71 void ResetTaskHandlerMutex(); 72 73 private: TaskManager()74 TaskManager() : canTaskRun_(false), isHandlerRunning_(false) {} ~TaskManager()75 ~TaskManager() {} 76 77 TaskManager(const TaskManager&) = delete; 78 TaskManager& operator=(const TaskManager&) = delete; 79 TaskManager(TaskManager&&) = delete; 80 TaskManager& operator=(TaskManager&&) = delete; 81 82 List<Task*> list_; /* the task list */ 83 bool canTaskRun_; 84 bool isHandlerRunning_; 85 }; 86 } // namespace OHOS 87 #endif // GRAPHIC_LITE_TASK_MANAGER_H 88