• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 "dm_thread_manager.h"
17 #include "dm_log.h"
18 
19 namespace OHOS {
20 namespace DistributedHardware {
21 DM_IMPLEMENT_SINGLE_INSTANCE(ThreadManager);
22 constexpr const char* DEVICE_MANAGER_THREAD_QUEUE = "device_manager_thread_queue";
Submit(const char * threadName,const std::function<void ()> & threadFunc)23 ffrt::task_handle ThreadManager::Submit(const char* threadName, const std::function<void()>& threadFunc)
24 {
25     if (ffrtQueue_ == nullptr) {
26         ffrtQueue_ = std::make_shared<ffrt::queue>(DEVICE_MANAGER_THREAD_QUEUE,
27             ffrt::queue_attr().qos(ffrt::qos_default));
28     }
29     return ffrtQueue_->submit_h(threadFunc, ffrt::task_attr().name(threadName));
30 }
31 
Wait(const ffrt::task_handle & handle)32 void ThreadManager::Wait(const ffrt::task_handle& handle)
33 {
34     if (ffrtQueue_ == nullptr) {
35         LOGE("ThreadManager Wait, ffrtQueue is null.");
36         return;
37     }
38     ffrtQueue_->wait(handle);
39 }
40 } // namespace DistributedHardware
41 } // namespace OHOS
42