1419b0af8Sopenharmony_ci/*
2419b0af8Sopenharmony_ci * Copyright (C) 2022 Huawei Technologies Co., Ltd.
3419b0af8Sopenharmony_ci * Decription: memory operation for gp sharedmem.
4419b0af8Sopenharmony_ci *
5419b0af8Sopenharmony_ci * This software is licensed under the terms of the GNU General Public
6419b0af8Sopenharmony_ci * License version 2, as published by the Free Software Foundation, and
7419b0af8Sopenharmony_ci * may be copied, distributed, and modified under those terms.
8419b0af8Sopenharmony_ci *
9419b0af8Sopenharmony_ci * This program is distributed in the hope that it will be useful,
10419b0af8Sopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of
11419b0af8Sopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12419b0af8Sopenharmony_ci * GNU General Public License for more details.
13419b0af8Sopenharmony_ci */
14419b0af8Sopenharmony_ci#ifndef MEM_H
15419b0af8Sopenharmony_ci#define MEM_H
16419b0af8Sopenharmony_ci#include <linux/types.h>
17419b0af8Sopenharmony_ci#include "teek_ns_client.h"
18419b0af8Sopenharmony_ci
19419b0af8Sopenharmony_ci#define PRE_ALLOCATE_SIZE (1024*1024)
20419b0af8Sopenharmony_ci#define MEM_POOL_ELEMENT_SIZE (64*1024)
21419b0af8Sopenharmony_ci#define MEM_POOL_ELEMENT_NR (8)
22419b0af8Sopenharmony_ci#define MEM_POOL_ELEMENT_ORDER (4)
23419b0af8Sopenharmony_ci
24419b0af8Sopenharmony_cistruct tc_ns_shared_mem *tc_mem_allocate(size_t len);
25419b0af8Sopenharmony_civoid tc_mem_free(struct tc_ns_shared_mem *shared_mem);
26419b0af8Sopenharmony_ci
27419b0af8Sopenharmony_cistatic inline void get_sharemem_struct(struct tc_ns_shared_mem *sharemem)
28419b0af8Sopenharmony_ci{
29419b0af8Sopenharmony_ci	if (sharemem != NULL)
30419b0af8Sopenharmony_ci		atomic_inc(&sharemem->usage);
31419b0af8Sopenharmony_ci}
32419b0af8Sopenharmony_ci
33419b0af8Sopenharmony_cistatic inline void put_sharemem_struct(struct tc_ns_shared_mem *sharemem)
34419b0af8Sopenharmony_ci{
35419b0af8Sopenharmony_ci	if (sharemem != NULL) {
36419b0af8Sopenharmony_ci		if (atomic_dec_and_test(&sharemem->usage))
37419b0af8Sopenharmony_ci			tc_mem_free(sharemem);
38419b0af8Sopenharmony_ci	}
39419b0af8Sopenharmony_ci}
40419b0af8Sopenharmony_ci
41419b0af8Sopenharmony_ci#endif
42