• 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 TASK_FACTORY_HPP
17 #define TASK_FACTORY_HPP
18 
19 #include "tm/cpu_task.h"
20 #include "util/cb_func.h"
21 
22 namespace ffrt {
23 
24 class TaskFactory {
25 public:
26     static TaskFactory &Instance();
27 
Alloc()28     static CPUEUTask *Alloc()
29     {
30         return Instance().alloc_();
31     }
32 
Free(CPUEUTask * task)33     static void Free(CPUEUTask *task)
34     {
35         Instance().free_(task);
36     }
37 
RegistCb(TaskAllocCB<CPUEUTask>::Alloc && alloc,TaskAllocCB<CPUEUTask>::Free && free)38     static void RegistCb(TaskAllocCB<CPUEUTask>::Alloc &&alloc, TaskAllocCB<CPUEUTask>::Free &&free)
39     {
40         Instance().alloc_ = std::move(alloc);
41         Instance().free_ = std::move(free);
42     }
43 
44 private:
45     TaskAllocCB<CPUEUTask>::Alloc alloc_;
46     TaskAllocCB<CPUEUTask>::Free free_;
47 };
48 
49 } /* namespace ffrt */
50 
51 #endif