15490a39dSopenharmony_ci/*
25490a39dSopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd.
35490a39dSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
45490a39dSopenharmony_ci * you may not use this file except in compliance with the License.
55490a39dSopenharmony_ci * You may obtain a copy of the License at
65490a39dSopenharmony_ci *
75490a39dSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
85490a39dSopenharmony_ci *
95490a39dSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
105490a39dSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
115490a39dSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
125490a39dSopenharmony_ci * See the License for the specific language governing permissions and
135490a39dSopenharmony_ci * limitations under the License.
145490a39dSopenharmony_ci */
155490a39dSopenharmony_ci#include "memory_guard.h"
165490a39dSopenharmony_ci#include <cstdint>
175490a39dSopenharmony_ci#include <malloc.h>
185490a39dSopenharmony_ci#include "intell_voice_log.h"
195490a39dSopenharmony_ci
205490a39dSopenharmony_ci#define LOG_TAG "MemoryGaurd"
215490a39dSopenharmony_ci
225490a39dSopenharmony_cinamespace OHOS {
235490a39dSopenharmony_cinamespace IntellVoiceUtils {
245490a39dSopenharmony_ciMemoryGuard::MemoryGuard()
255490a39dSopenharmony_ci{
265490a39dSopenharmony_ci#ifdef CONFIG_USE_JEMALLOC_DFX_INTF
275490a39dSopenharmony_ci    // 0 indicates success
285490a39dSopenharmony_ci    int32_t ret1 = mallopt(M_SET_THREAD_CACHE, M_THREAD_CACHE_DISABLE);
295490a39dSopenharmony_ci    int32_t ret2 = mallopt(M_DELAYED_FREE, M_DELAYED_FREE_DISABLE);
305490a39dSopenharmony_ci    INTELL_VOICE_LOG_INFO("disable tcache and delay free, result:%{public}d, %{public}d", ret1, ret2);
315490a39dSopenharmony_ci#endif
325490a39dSopenharmony_ci}
335490a39dSopenharmony_ci
345490a39dSopenharmony_ciMemoryGuard::~MemoryGuard()
355490a39dSopenharmony_ci{
365490a39dSopenharmony_ci#ifdef CONFIG_USE_JEMALLOC_DFX_INTF
375490a39dSopenharmony_ci    int32_t err = mallopt(M_FLUSH_THREAD_CACHE, 0);
385490a39dSopenharmony_ci    INTELL_VOICE_LOG_INFO("flush cache, result: %{public}d", err);
395490a39dSopenharmony_ci#endif
405490a39dSopenharmony_ci}
415490a39dSopenharmony_ci}
425490a39dSopenharmony_ci}