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