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 #ifndef IAM_THREAD_HANDLER_IMPL_H
17 #define IAM_THREAD_HANDLER_IMPL_H
18 
19 #include <mutex>
20 
21 #include "nocopyable.h"
22 
23 #include "thread_handler.h"
24 #include "thread_pool.h"
25 
26 namespace OHOS {
27 namespace UserIam {
28 namespace UserAuth {
29 class ThreadHandlerImpl : public ThreadHandler, NoCopyable {
30 public:
31     ThreadHandlerImpl(std::string name, bool canSuspend);
32     ~ThreadHandlerImpl() override;
33     void PostTask(const Task &task) override;
34     void EnsureTask(const Task &task) override;
35     void Suspend() override;
36 
37 private:
38     OHOS::ThreadPool pool_;
39     bool canSuspend_ = false;
40 
41     std::recursive_mutex mutex_;
42     bool isSuspended_ = false;
43 };
44 } // namespace UserAuth
45 } // namespace UserIam
46 } // namespace OHOS
47 
48 #endif // IAM_THREAD_HANDLER_IMPL_H