• 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 #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 const char* GetCurrentProcessName();
32 
33 class FFRTFacade {
34 public:
GetEUInstance()35     static inline ExecuteUnit& GetEUInstance()
36     {
37         return Instance().GetEUInstanceImpl();
38     }
39 
GetDMInstance()40     static inline DependenceManager& GetDMInstance()
41     {
42         return Instance().GetDMInstanceImpl();
43     }
44 
GetPPInstance()45     static inline PollerProxy& GetPPInstance()
46     {
47         return Instance().GetPPInstanceImpl();
48     }
49 
GetDWInstance()50     static inline DelayedWorker& GetDWInstance()
51     {
52         return Instance().GetDWInstanceImpl();
53     }
54 
GetSchedInstance()55     static inline FFRTScheduler* GetSchedInstance()
56     {
57         return Instance().GetSchedInstanceImpl();
58     }
59 
GetIoPPInstance()60     static inline IOPoller& GetIoPPInstance()
61     {
62         return Instance().GetIoPPInstanceImpl();
63     }
64 
GetCSAInstance()65     static inline CoStackAttr* GetCSAInstance()
66     {
67         return Instance().GetCSAInstanceImpl();
68     }
69 
GetQMInstance()70     static inline QueueMonitor& GetQMInstance()
71     {
72         return Instance().GetQMInstanceImpl();
73     }
74 
GetWMInstance()75     static inline WorkerMonitor& GetWMInstance()
76     {
77         return Instance().GetWMInstanceImpl();
78     }
79 
80 private:
81     FFRTFacade();
82 
Instance()83     static FFRTFacade& Instance()
84     {
85         static FFRTFacade facade;
86         return facade;
87     }
88 
GetEUInstanceImpl()89     inline ExecuteUnit& GetEUInstanceImpl()
90     {
91         return ExecuteUnit::Instance();
92     }
93 
GetDMInstanceImpl()94     inline DependenceManager& GetDMInstanceImpl()
95     {
96         return DependenceManager::Instance();
97     }
98 
GetPPInstanceImpl()99     inline PollerProxy& GetPPInstanceImpl()
100     {
101         return PollerProxy::Instance();
102     }
103 
GetDWInstanceImpl()104     inline DelayedWorker& GetDWInstanceImpl()
105     {
106         return DelayedWorker::GetInstance();
107     }
108 
GetSchedInstanceImpl()109     inline FFRTScheduler* GetSchedInstanceImpl()
110     {
111         return FFRTScheduler::Instance();
112     }
113 
GetIoPPInstanceImpl()114     inline IOPoller& GetIoPPInstanceImpl()
115     {
116         return GetIOPoller();
117     }
118 
GetCSAInstanceImpl()119     inline CoStackAttr* GetCSAInstanceImpl()
120     {
121         return CoStackAttr::Instance();
122     }
123 
GetQMInstanceImpl()124     inline QueueMonitor& GetQMInstanceImpl()
125     {
126         return QueueMonitor::GetInstance();
127     }
128 
GetWMInstanceImpl()129     inline WorkerMonitor& GetWMInstanceImpl()
130     {
131         return WorkerMonitor::GetInstance();
132     }
133 };
134 
135 } // namespace FFRT
136 #endif