• 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 
16 #include "eu/execute_unit.h"
17 
18 #include "internal_inc/config.h"
19 #include "eu/cpuworker_manager.h"
20 
21 namespace ffrt {
ExecuteUnit()22 ExecuteUnit::ExecuteUnit()
23 {
24     auto create = [&](const DevType dev) {
25         std::unique_ptr<WorkerManager> manager;
26         switch (dev) {
27             case DevType::CPU:
28                 manager = std::unique_ptr<WorkerManager>(new (std::nothrow) CPUWorkerManager());
29                 break;
30             default:
31                 break;
32         }
33 
34         if (!manager) {
35             FFRT_LOGE("create workerManager fail, devType %d", static_cast<size_t>(dev));
36             return;
37         }
38 
39         wManager[static_cast<size_t>(dev)] = std::move(manager);
40     };
41 
42     for (size_t dev = 0; dev < static_cast<size_t>(DevType::DEVMAX); ++dev) {
43         create(static_cast<DevType>(dev));
44     }
45 }
46 
BindTG(const DevType dev,QoS & qos)47 ThreadGroup* ExecuteUnit::BindTG(const DevType dev, QoS& qos)
48 {
49     return wManager[static_cast<size_t>(dev)]->JoinTG(qos);
50 }
51 
BindWG(const DevType dev,QoS & qos)52 void ExecuteUnit::BindWG(const DevType dev, QoS& qos)
53 {
54     return wManager[static_cast<size_t>(dev)]->JoinRtg(qos);
55 }
56 
UnbindTG(const DevType dev,QoS & qos)57 void ExecuteUnit::UnbindTG(const DevType dev, QoS& qos)
58 {
59     wManager[static_cast<size_t>(dev)]->LeaveTG(qos);
60 }
61 } // namespace ffrt
62