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 return Instance().GetSchedInstanceImpl(); 61 } 62 GetIoPPInstance()63 static inline IOPoller& GetIoPPInstance() 64 { 65 static IOPoller& inst = Instance().GetIoPPInstanceImpl(); 66 return inst; 67 } 68 GetCSAInstance()69 static inline CoStackAttr* GetCSAInstance() 70 { 71 return Instance().GetCSAInstanceImpl(); 72 } 73 GetQMInstance()74 static inline QueueMonitor& GetQMInstance() 75 { 76 static QueueMonitor& inst = Instance().GetQMInstanceImpl(); 77 return inst; 78 } 79 GetWMInstance()80 static inline WorkerMonitor& GetWMInstance() 81 { 82 static WorkerMonitor& inst = Instance().GetWMInstanceImpl(); 83 return inst; 84 } 85 86 private: 87 FFRTFacade(); 88 Instance()89 static FFRTFacade& Instance() 90 { 91 static FFRTFacade facade; 92 return facade; 93 } 94 GetEUInstanceImpl()95 inline ExecuteUnit& GetEUInstanceImpl() 96 { 97 return ExecuteUnit::Instance(); 98 } 99 GetDMInstanceImpl()100 inline DependenceManager& GetDMInstanceImpl() 101 { 102 return DependenceManager::Instance(); 103 } 104 GetPPInstanceImpl()105 inline PollerProxy& GetPPInstanceImpl() 106 { 107 return PollerProxy::Instance(); 108 } 109 GetDWInstanceImpl()110 inline DelayedWorker& GetDWInstanceImpl() 111 { 112 return DelayedWorker::GetInstance(); 113 } 114 GetSchedInstanceImpl()115 inline FFRTScheduler* GetSchedInstanceImpl() 116 { 117 return FFRTScheduler::Instance(); 118 } 119 GetIoPPInstanceImpl()120 inline IOPoller& GetIoPPInstanceImpl() 121 { 122 return GetIOPoller(); 123 } 124 GetCSAInstanceImpl()125 inline CoStackAttr* GetCSAInstanceImpl() 126 { 127 return CoStackAttr::Instance(); 128 } 129 GetQMInstanceImpl()130 inline QueueMonitor& GetQMInstanceImpl() 131 { 132 return QueueMonitor::GetInstance(); 133 } 134 GetWMInstanceImpl()135 inline WorkerMonitor& GetWMInstanceImpl() 136 { 137 return WorkerMonitor::GetInstance(); 138 } 139 }; 140 141 } // namespace FFRT 142 #endif