• 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 #include "thread_handler_singleton_impl.h"
16 
17 #include <cstdint>
18 #include <functional>
19 #include <future>
20 #include <memory>
21 
22 #include "nocopyable.h"
23 
24 #include "iam_logger.h"
25 #include "iam_ptr.h"
26 #include "relative_timer.h"
27 #include "thread_handler_manager.h"
28 #include "xcollie_helper.h"
29 
30 #define LOG_TAG "USER_AUTH_SA"
31 
32 namespace OHOS {
33 namespace UserIam {
34 namespace UserAuth {
35 using namespace OHOS;
36 using namespace OHOS::UserIam::Common;
37 constexpr uint32_t TASK_BLOCK_MONITOR_TIMEOUT = 20;
38 
PostTask(const Task & task)39 void ThreadHandlerSingletonImpl::PostTask(const Task &task)
40 {
41     RelativeTimer::GetInstance().Register(task, 0);
42 
43     auto taskBlockMonitor = MakeShared<XCollieHelper>("taskBlockMonitor", TASK_BLOCK_MONITOR_TIMEOUT);
44     if (taskBlockMonitor == nullptr) {
45         IAM_LOGE("taskBlockMonitor is nullptr");
46         return;
47     }
48 
49     RelativeTimer::GetInstance().Register(
50         [taskBlockMonitor] {
51             (void)taskBlockMonitor;
52         },
53         0);
54 }
55 
EnsureTask(const Task & task)56 void ThreadHandlerSingletonImpl::EnsureTask(const Task &task)
57 {
58     std::promise<void> ensure;
59     auto callback = [&ensure]() {
60         ensure.set_value();
61         return;
62     };
63     PostTask(task);
64     PostTask(callback);
65     ensure.get_future().get();
66 }
67 
Suspend()68 void ThreadHandlerSingletonImpl::Suspend()
69 {
70     IAM_LOGE("can not suspend");
71 }
72 } // namespace UserAuth
73 } // namespace UserIam
74 } // namespace OHOS