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 #ifndef DFX_PARAM_H
16 #define DFX_PARAM_H
17 
18 #include <cstdint>
19 #if defined(ENABLE_PARAMETER)
20 #include <mutex>
21 #include "parameter.h"
22 #include "parameters.h"
23 #endif
24 
25 namespace OHOS {
26 namespace HiviewDFX {
27 namespace {
28 [[maybe_unused]] constexpr char MIXSTACK_ENABLED_KEY[] = "faultloggerd.priv.mixstack.enabled";
29 }
30 
31 #if defined(ENABLE_PARAMETER)
32 #define GEN_ENABLE_PARAM_FUNC(FuncName, EnableKey, DefValue, ExpValue) \
33     __attribute__((noinline)) static bool FuncName() \
34     { \
35         static bool ret = true; \
36         static std::once_flag flag; \
37         std::call_once(flag, [&] { \
38             if (OHOS::system::GetParameter(EnableKey, DefValue) == ExpValue) { \
39                 ret = true; \
40             } else { \
41                 ret = false; \
42             } \
43         }); \
44         return ret; \
45     }
46 #else
47 #define GEN_ENABLE_PARAM_FUNC(FuncName, EnableKey, DefValue, ExpValue) \
48     __attribute__((noinline)) static bool FuncName() \
49     { \
50         return false; \
51     }
52 #endif
53 
54 class DfxParam {
55 public:
56     GEN_ENABLE_PARAM_FUNC(EnableMixstack, MIXSTACK_ENABLED_KEY, "true", "true");
57 };
58 } // namespace HiviewDFX
59 } // namespace OHOS
60 #endif