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_MANAGER_H 17 #define IAM_THREAD_HANDLER_MANAGER_H 18 19 #include <map> 20 #include <mutex> 21 #include <string> 22 23 #include "thread_handler.h" 24 25 namespace OHOS { 26 namespace UserIam { 27 namespace UserAuth { 28 const std::string SINGLETON_THREAD_NAME = "ThreadHandler"; 29 class ThreadHandlerManager { 30 public: 31 static ThreadHandlerManager &GetInstance(); 32 ThreadHandlerManager(); 33 ~ThreadHandlerManager() = default; 34 35 bool CreateThreadHandler(const std::string &name); 36 void DestroyThreadHandler(const std::string &name); 37 void DeleteThreadHandler(const std::string &name); 38 std::shared_ptr<ThreadHandler> GetThreadHandler(const std::string &name); 39 void PostTask(const std::string &name, const std::function<void()> &task); 40 41 private: 42 std::recursive_mutex mutex_; 43 std::map<std::string, std::shared_ptr<ThreadHandler>> threadHandlerMap_; 44 }; 45 } // namespace UserAuth 46 } // namespace UserIam 47 } // namespace OHOS 48 49 #endif // IAM_THREAD_HANDLER_MANAGER_H