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 #include <dlfcn.h>
16 #include "sched/task_scheduler.h"
17 #include "eu/co_routine.h"
18 #include "eu/execute_unit.h"
19 #include "eu/sexecute_unit.h"
20 #include "dm/dependence_manager.h"
21 #include "dm/sdependence_manager.h"
22 #include "dfx/log/ffrt_log_api.h"
23 #include "util/singleton_register.h"
24 #include "util/slab.h"
25 #include "tm/task_factory.h"
26 #include "qos.h"
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
ffrt_init()31 __attribute__((constructor)) static void ffrt_init()
32 {
33     ffrt::TaskFactory::RegistCb(
34         [] () -> ffrt::CPUEUTask* {
35             return static_cast<ffrt::CPUEUTask*>(ffrt::SimpleAllocator<ffrt::SCPUEUTask>::AllocMem());
36         },
37         [] (ffrt::CPUEUTask* task) {
38             ffrt::SimpleAllocator<ffrt::SCPUEUTask>::FreeMem(static_cast<ffrt::SCPUEUTask*>(task));
39     },
40     ffrt::SimpleAllocator<ffrt::SCPUEUTask>::getUnfreedMem,
41     ffrt::SimpleAllocator<ffrt::SCPUEUTask>::LockMem,
42     ffrt::SimpleAllocator<ffrt::SCPUEUTask>::UnlockMem);
43     ffrt::SchedulerFactory::RegistCb(
44         [] () -> ffrt::TaskScheduler* { return new ffrt::TaskScheduler{new ffrt::FIFOQueue()}; },
45         [] (ffrt::TaskScheduler* schd) { delete schd; });
46     CoRoutineFactory::RegistCb(
47         [] (ffrt::CPUEUTask* task, bool timeOut) -> void {CoWake(task, timeOut);});
48     ffrt::DependenceManager::RegistInsCb(ffrt::SDependenceManager::Instance);
49     ffrt::ExecuteUnit::RegistInsCb(ffrt::SExecuteUnit::Instance);
50     ffrt::FFRTScheduler::RegistInsCb(ffrt::SFFRTScheduler::Instance);
51     ffrt::SetFuncQosMap(ffrt::QoSMap);
52     ffrt::SetFuncQosMax(ffrt::QoSMax);
53 }
54 #ifdef __cplusplus
55 }
56 #endif