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 #ifdef FFRT_ASYNC_STACKTRACE 28 #include "dfx/async_stack/ffrt_async_stack.h" 29 #endif 30 31 #ifdef __cplusplus 32 extern "C" { 33 #endif ffrt_init()34__attribute__((constructor)) static void ffrt_init() 35 { 36 ffrt::TaskFactory::RegistCb( 37 [] () -> ffrt::CPUEUTask* { 38 return static_cast<ffrt::CPUEUTask*>(ffrt::SimpleAllocator<ffrt::SCPUEUTask>::AllocMem()); 39 }, 40 [] (ffrt::CPUEUTask* task) { 41 ffrt::SimpleAllocator<ffrt::SCPUEUTask>::FreeMem(static_cast<ffrt::SCPUEUTask*>(task)); 42 }); 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 } FfrtDeinit(void)54__attribute__((destructor)) static void FfrtDeinit(void) 55 { 56 #ifdef FFRT_ASYNC_STACKTRACE 57 ffrt::CloseAsyncStackLibHandle(); 58 #endif 59 } 60 #ifdef __cplusplus 61 } 62 #endif