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 #ifndef FFRT_FUNC_MANAGER_HPP 17 #define FFRT_FUNC_MANAGER_HPP 18 19 #include "ffrt_inner.h" 20 #include "c/executor_task.h" 21 22 namespace ffrt { 23 class FuncManager { 24 public: 25 FuncManager(const FuncManager&) = delete; 26 FuncManager& operator=(const FuncManager&) = delete; ~FuncManager()27 ~FuncManager() 28 { 29 } 30 31 // 获取FuncManager的单例 Instance()32 static inline FuncManager* Instance() 33 { 34 static FuncManager func_mg; 35 return &func_mg; 36 } 37 insert(ffrt_executor_task_type_t type,ffrt_executor_task_func func)38 void insert(ffrt_executor_task_type_t type, ffrt_executor_task_func func) 39 { 40 func_map[type] = func; 41 } 42 getFunc(ffrt_executor_task_type_t type)43 ffrt_executor_task_func getFunc(ffrt_executor_task_type_t type) 44 { 45 if (func_map.find(type) == func_map.end()) { 46 return nullptr; 47 } 48 return func_map[type]; 49 } 50 51 private: FuncManager()52 FuncManager() 53 { 54 func_map[ffrt_io_task] = nullptr; 55 func_map[ffrt_uv_task] = nullptr; 56 } 57 std::unordered_map<ffrt_executor_task_type_t, ffrt_executor_task_func> func_map; 58 }; 59 } 60 #endif 61