1 /* 2 * Copyright (c) 2023 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 "util/ffrt_facade.h" 16 #include "dfx/log/ffrt_log_api.h" 17 18 namespace { 19 std::atomic<bool> g_exitFlag { false }; 20 std::shared_mutex g_exitMtx; 21 } 22 23 namespace ffrt { GetExitFlag()24bool GetExitFlag() 25 { 26 return g_exitFlag.load(); 27 } 28 GetExitMtx()29std::shared_mutex& GetExitMtx() 30 { 31 return g_exitMtx; 32 } 33 34 class ProcessExitManager { 35 public: Instance()36 static ProcessExitManager& Instance() 37 { 38 static ProcessExitManager instance; 39 return instance; 40 } 41 42 ProcessExitManager(const ProcessExitManager&) = delete; 43 ProcessExitManager& operator=(const ProcessExitManager&) = delete; 44 45 private: ProcessExitManager()46 ProcessExitManager() {} 47 ~ProcessExitManager()48 ~ProcessExitManager() 49 { 50 FFRT_LOGW("ProcessExitManager destruction enter"); 51 std::unique_lock lock(g_exitMtx); 52 g_exitFlag.store(true); 53 } 54 }; 55 FFRTFacade()56FFRTFacade::FFRTFacade() 57 { 58 DependenceManager::Instance(); 59 ProcessExitManager::Instance(); 60 InitWhiteListFlag(); 61 } 62 } // namespace FFRT