• 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/stask_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/white_list.h"
25 #include "tm/task_factory.h"
26 #include "tm/io_task.h"
27 #include "tm/uv_task.h"
28 #include "tm/queue_task.h"
29 #include "util/slab.h"
30 #include "qos.h"
31 #ifdef FFRT_ASYNC_STACKTRACE
32 #include "dfx/async_stack/ffrt_async_stack.h"
33 #endif
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
RegistCommonTaskFactory()38 void RegistCommonTaskFactory()
39 {
40     ffrt::RegisterTaskFactoryCallbacks<ffrt::QueueTask>();
41     ffrt::RegisterTaskFactoryCallbacks<ffrt::IOTask>();
42     ffrt::RegisterTaskFactoryCallbacks<ffrt::UVTask>();
43 }
44 
ffrt_init()45 __attribute__((constructor)) static void ffrt_init()
46 {
47     RegistCommonTaskFactory();
48     ffrt::RegisterTaskFactoryCallbacks<ffrt::CPUEUTask, ffrt::SCPUEUTask>();
49     ffrt::SchedulerFactory::RegistCb(
50         [] () -> ffrt::TaskScheduler* { return new ffrt::STaskScheduler(); },
51         [] (ffrt::TaskScheduler* schd) { delete schd; });
52     CoRoutineFactory::RegistCb(
53         [] (ffrt::CoTask* task, CoWakeType type) -> void {CoWake(task, type);});
54     ffrt::DependenceManager::RegistInsCb(ffrt::SDependenceManager::Instance);
55     ffrt::ExecuteUnit::RegistInsCb(ffrt::SExecuteUnit::Instance);
56     ffrt::SetFuncQosMap(ffrt::QoSMap);
57     ffrt::SetFuncQosMax(ffrt::QoSMax);
58 }
FfrtDeinit(void)59 __attribute__((destructor)) static void FfrtDeinit(void)
60 {
61 #ifdef FFRT_ASYNC_STACKTRACE
62     ffrt::CloseAsyncStackLibHandle();
63 #endif
64 }
65 
ffrt_child_init(void)66 void ffrt_child_init(void)
67 {
68     ffrt_init();
69 }
70 #ifdef __cplusplus
71 }
72 #endif