• 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 #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::CPUEUTask* task) {
42             return ffrt::SimpleAllocator<ffrt::SCPUEUTask>::HasBeenFreed(static_cast<ffrt::SCPUEUTask*>(task));
43         },
44     ffrt::SimpleAllocator<ffrt::SCPUEUTask>::LockMem,
45     ffrt::SimpleAllocator<ffrt::SCPUEUTask>::UnlockMem);
46     ffrt::SchedulerFactory::RegistCb(
47         [] () -> ffrt::TaskScheduler* { return new ffrt::TaskScheduler{new ffrt::FIFOQueue()}; },
48         [] (ffrt::TaskScheduler* schd) { delete schd; });
49     CoRoutineFactory::RegistCb(
50         [] (ffrt::CPUEUTask* task, bool timeOut) -> void {CoWake(task, timeOut);});
51     ffrt::DependenceManager::RegistInsCb(ffrt::SDependenceManager::Instance);
52     ffrt::ExecuteUnit::RegistInsCb(ffrt::SExecuteUnit::Instance);
53     ffrt::FFRTScheduler::RegistInsCb(ffrt::SFFRTScheduler::Instance);
54     ffrt::SetFuncQosMap(ffrt::QoSMap);
55     ffrt::SetFuncQosMax(ffrt::QoSMax);
56 }
57 #ifdef __cplusplus
58 }
59 #endif