14f7ff21fSopenharmony_ci/*
24f7ff21fSopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd.
34f7ff21fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
44f7ff21fSopenharmony_ci * you may not use this file except in compliance with the License.
54f7ff21fSopenharmony_ci * You may obtain a copy of the License at
64f7ff21fSopenharmony_ci *
74f7ff21fSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
84f7ff21fSopenharmony_ci *
94f7ff21fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
104f7ff21fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
114f7ff21fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
124f7ff21fSopenharmony_ci * See the License for the specific language governing permissions and
134f7ff21fSopenharmony_ci * limitations under the License.
144f7ff21fSopenharmony_ci */
154f7ff21fSopenharmony_ci#include "memory_guard.h"
164f7ff21fSopenharmony_ci
174f7ff21fSopenharmony_ci#include "iam_logger.h"
184f7ff21fSopenharmony_ci#include "malloc.h"
194f7ff21fSopenharmony_ci
204f7ff21fSopenharmony_ci#define LOG_TAG "FINGERPRINT_AUTH_SA"
214f7ff21fSopenharmony_ci
224f7ff21fSopenharmony_cinamespace OHOS {
234f7ff21fSopenharmony_cinamespace UserIam {
244f7ff21fSopenharmony_cinamespace FingerprintAuth {
254f7ff21fSopenharmony_ciMemoryGuard::MemoryGuard()
264f7ff21fSopenharmony_ci{
274f7ff21fSopenharmony_ci#ifdef CONFIG_USE_JEMALLOC_DFX_INTF
284f7ff21fSopenharmony_ci    int32_t ret1 = mallopt(M_SET_THREAD_CACHE, M_THREAD_CACHE_DISABLE);
294f7ff21fSopenharmony_ci    int32_t ret2 = mallopt(M_DELAYED_FREE, M_DELAYED_FREE_DISABLE);
304f7ff21fSopenharmony_ci    IAM_LOGI("disable thread cache and delay free, result[%{public}d, %{public}d]", ret1, ret2);
314f7ff21fSopenharmony_ci#endif
324f7ff21fSopenharmony_ci}
334f7ff21fSopenharmony_ci
344f7ff21fSopenharmony_ciMemoryGuard::~MemoryGuard()
354f7ff21fSopenharmony_ci{
364f7ff21fSopenharmony_ci#ifdef CONFIG_USE_JEMALLOC_DFX_INTF
374f7ff21fSopenharmony_ci    int32_t ret = mallopt(M_FLUSH_THREAD_CACHE, 0);
384f7ff21fSopenharmony_ci    IAM_LOGI("flush thread cache, result: %{public}d", ret);
394f7ff21fSopenharmony_ci#endif
404f7ff21fSopenharmony_ci}
414f7ff21fSopenharmony_ci} // namespace FingerprintAuth
424f7ff21fSopenharmony_ci} // namespace UserIam
434f7ff21fSopenharmony_ci} // namespace OHOS