• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 "libpandabase/taskmanager/task_manager.h"
17 
18 namespace ark::taskmanager {
19 
20 TaskManager *TaskManager::inst_ = nullptr;
21 
22 /*static*/
Start(size_t workerCount,TaskTimeStatsType statsType)23 void TaskManager::Start(size_t workerCount, TaskTimeStatsType statsType)
24 {
25     ASSERT_PRINT(inst_ == nullptr, "Try to create task manager while it exists");
26     inst_ = new TaskManager(workerCount, statsType);
27 }
28 
29 /*static*/
IsUsed()30 bool TaskManager::IsUsed()
31 {
32     return inst_ != nullptr;
33 }
34 
35 /*static*/
Finish()36 void TaskManager::Finish()
37 {
38     ASSERT_PRINT(inst_ != nullptr, "Try to destroy task manager while it doesn't exists");
39     delete inst_;
40     inst_ = nullptr;
41 }
42 
43 /*static*/
GetTaskQueue(QueueId id)44 TaskQueueInterface *TaskManager::GetTaskQueue(QueueId id)
45 {
46     ASSERT(inst_ != nullptr);
47     return inst_->queueSet_.GetQueue(id);
48 }
49 
50 /*static*/
SetWorkersCount(size_t count)51 void TaskManager::SetWorkersCount(size_t count)
52 {
53     inst_->scheduler_.SetCountOfWorkers(count);
54 }
55 
56 /*static*/
GetWorkersCount()57 size_t TaskManager::GetWorkersCount()
58 {
59     return inst_->scheduler_.GetCountOfWorkers();
60 }
61 
TaskManager(size_t workerCount,TaskTimeStatsType statsType)62 TaskManager::TaskManager(size_t workerCount, TaskTimeStatsType statsType)
63     : waitList_(), queueSet_(&waitList_, statsType), scheduler_(workerCount, &waitList_, &queueSet_)
64 {
65     queueSet_.SetCallbacks([] { TaskManager::inst_->scheduler_.SignalWorkers(); });
66 }
67 
68 }  // namespace ark::taskmanager
69