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 #include "preferences_manager_mock.h"
17 
18 namespace OHOS {
19 namespace MMI {
20 
21 std::shared_ptr<IPreferenceManager> IPreferenceManager::instance_;
22 std::mutex IPreferenceManager::mutex_;
23 
GetInstance()24 std::shared_ptr<IPreferenceManager> IPreferenceManager::GetInstance()
25 {
26     if (instance_ == nullptr) {
27         std::lock_guard<std::mutex> lock(mutex_);
28         if (instance_ == nullptr) {
29             instance_ = PreferencesManagerMock::GetInstance();
30         }
31     }
32     return instance_;
33 }
34 
35 std::shared_ptr<PreferencesManagerMock> PreferencesManagerMock::instance_;
36 std::mutex PreferencesManagerMock::mutex_;
37 
GetInstance()38 std::shared_ptr<PreferencesManagerMock> PreferencesManagerMock::GetInstance()
39 {
40     if (instance_ == nullptr) {
41         std::lock_guard<std::mutex> lock(mutex_);
42         if (instance_ == nullptr) {
43             instance_ = std::make_shared<PreferencesManagerMock>();
44         }
45     }
46     return instance_;
47 }
48 } // namespace MMI
49 } // namespace OHOS