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