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