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/execute_unit.h" 20 #include "dm/dependence_manager.h" 21 #include "sync/poller.h" 22 #include "sync/delayed_worker.h" 23 namespace ffrt { 24 bool GetExitFlag(); 25 std::shared_mutex& GetExitMtx(); 26 27 class FFRTFacade { 28 public: GetEUInstance()29 static inline ExecuteUnit& GetEUInstance() 30 { 31 static ExecuteUnit& inst = Instance().GetEUInstanceImpl(); 32 return inst; 33 } 34 GetDMInstance()35 static inline DependenceManager& GetDMInstance() 36 { 37 static DependenceManager& inst = Instance().GetDMInstanceImpl(); 38 return inst; 39 } 40 GetPPInstance()41 static inline PollerProxy& GetPPInstance() 42 { 43 PollerProxy& inst = Instance().GetPPInstanceImpl(); 44 return inst; 45 } 46 GetDWInstance()47 static inline DelayedWorker& GetDWInstance() 48 { 49 DelayedWorker& inst = Instance().GetDWInstanceImpl(); 50 return inst; 51 } 52 GetSchedInstance()53 static inline FFRTScheduler* GetSchedInstance() 54 { 55 FFRTScheduler* inst = Instance().GetSchedInstanceImpl(); 56 return inst; 57 } 58 59 private: 60 FFRTFacade(); 61 Instance()62 static FFRTFacade& Instance() 63 { 64 static FFRTFacade facade; 65 return facade; 66 } 67 GetEUInstanceImpl()68 inline ExecuteUnit& GetEUInstanceImpl() 69 { 70 return ExecuteUnit::Instance(); 71 } 72 GetDMInstanceImpl()73 inline DependenceManager& GetDMInstanceImpl() 74 { 75 return DependenceManager::Instance(); 76 } 77 GetPPInstanceImpl()78 inline PollerProxy& GetPPInstanceImpl() 79 { 80 return PollerProxy::Instance(); 81 } 82 GetDWInstanceImpl()83 inline DelayedWorker& GetDWInstanceImpl() 84 { 85 return DelayedWorker::GetInstance(); 86 } 87 GetSchedInstanceImpl()88 inline FFRTScheduler* GetSchedInstanceImpl() 89 { 90 return FFRTScheduler::Instance(); 91 } 92 }; 93 94 } // namespace FFRT 95 #endif