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 #ifndef UTIL_FFRTFACADE_HPP 16 #define UTIL_FFRTFACADE_HPP 17 #include "tm/cpu_task.h" 18 #include "sched/scheduler.h" 19 #include "eu/co_routine.h" 20 #include "eu/execute_unit.h" 21 #include "dm/dependence_manager.h" 22 #include "queue/queue_monitor.h" 23 #include "sync/delayed_worker.h" 24 #include "sync/poller.h" 25 #include "sync/io_poller.h" 26 #include "util/worker_monitor.h" 27 28 namespace ffrt { 29 bool GetExitFlag(); 30 std::shared_mutex& GetExitMtx(); 31 32 class FFRTFacade { 33 public: GetEUInstance()34 static inline ExecuteUnit& GetEUInstance() 35 { 36 static ExecuteUnit& inst = Instance().GetEUInstanceImpl(); 37 return inst; 38 } 39 GetDMInstance()40 static inline DependenceManager& GetDMInstance() 41 { 42 static DependenceManager& inst = Instance().GetDMInstanceImpl(); 43 return inst; 44 } 45 GetPPInstance()46 static inline PollerProxy& GetPPInstance() 47 { 48 static PollerProxy& inst = Instance().GetPPInstanceImpl(); 49 return inst; 50 } 51 GetDWInstance()52 static inline DelayedWorker& GetDWInstance() 53 { 54 static DelayedWorker& inst = Instance().GetDWInstanceImpl(); 55 return inst; 56 } 57 GetSchedInstance()58 static inline FFRTScheduler* GetSchedInstance() 59 { 60 static FFRTScheduler* inst = Instance().GetSchedInstanceImpl(); 61 return inst; 62 } 63 GetIoPPInstance()64 static inline IOPoller& GetIoPPInstance() 65 { 66 static IOPoller& inst = Instance().GetIoPPInstanceImpl(); 67 return inst; 68 } 69 GetCSAInstance()70 static inline CoStackAttr* GetCSAInstance() 71 { 72 static CoStackAttr* inst = Instance().GetCSAInstanceImpl(); 73 return inst; 74 } 75 GetQMInstance()76 static inline QueueMonitor& GetQMInstance() 77 { 78 static QueueMonitor& inst = Instance().GetQMInstanceImpl(); 79 return inst; 80 } 81 GetWMInstance()82 static inline WorkerMonitor& GetWMInstance() 83 { 84 static WorkerMonitor& inst = Instance().GetWMInstanceImpl(); 85 return inst; 86 } 87 88 private: 89 FFRTFacade(); 90 Instance()91 static FFRTFacade& Instance() 92 { 93 static FFRTFacade facade; 94 return facade; 95 } 96 GetEUInstanceImpl()97 inline ExecuteUnit& GetEUInstanceImpl() 98 { 99 return ExecuteUnit::Instance(); 100 } 101 GetDMInstanceImpl()102 inline DependenceManager& GetDMInstanceImpl() 103 { 104 return DependenceManager::Instance(); 105 } 106 GetPPInstanceImpl()107 inline PollerProxy& GetPPInstanceImpl() 108 { 109 return PollerProxy::Instance(); 110 } 111 GetDWInstanceImpl()112 inline DelayedWorker& GetDWInstanceImpl() 113 { 114 return DelayedWorker::GetInstance(); 115 } 116 GetSchedInstanceImpl()117 inline FFRTScheduler* GetSchedInstanceImpl() 118 { 119 return FFRTScheduler::Instance(); 120 } 121 GetIoPPInstanceImpl()122 inline IOPoller& GetIoPPInstanceImpl() 123 { 124 return GetIOPoller(); 125 } 126 GetCSAInstanceImpl()127 inline CoStackAttr* GetCSAInstanceImpl() 128 { 129 return CoStackAttr::Instance(); 130 } 131 GetQMInstanceImpl()132 inline QueueMonitor& GetQMInstanceImpl() 133 { 134 return QueueMonitor::GetInstance(); 135 } 136 GetWMInstanceImpl()137 inline WorkerMonitor& GetWMInstanceImpl() 138 { 139 return WorkerMonitor::GetInstance(); 140 } 141 }; 142 143 } // namespace FFRT 144 #endif