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