0ff112689eb21ec444a130bdae23cb0172cd1c12
[ric-plt/submgr.git] / e2ap / libe2ap_wrapper / memtrack.h
1 /*
2 ==================================================================================
3   Copyright (c) 2019 AT&T Intellectual Property.
4   Copyright (c) 2019 Nokia
5
6    Licensed under the Apache License, Version 2.0 (the "License");
7    you may not use this file except in compliance with the License.
8    You may obtain a copy of the License at
9
10        http://www.apache.org/licenses/LICENSE-2.0
11
12    Unless required by applicable law or agreed to in writing, software
13    distributed under the License is distributed on an "AS IS" BASIS,
14    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15    See the License for the specific language governing permissions and
16    limitations under the License.
17 ==================================================================================
18 */
19
20 #ifndef __MEMTRACK_H__
21 #define __MEMTRACK_H__
22
23
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27         
28 /*
29  *
30  */
31 typedef struct mem_track_s{
32     struct mem_track_s *next;
33     size_t  sz;
34     unsigned char ptr[];
35 }mem_track_t;
36
37
38 /*
39  *
40  */
41 typedef struct mem_track_hdr_s{
42     struct mem_track_s *next;
43 }mem_track_hdr_t;
44
45 #define MEM_TRACK_HDR_INIT {0}
46
47
48 /*
49  *
50  */
51 void mem_track_init(mem_track_hdr_t *curr);
52
53 void* mem_track_alloc(mem_track_hdr_t *curr, size_t sz);
54
55 void mem_track_free(mem_track_hdr_t *curr);
56
57
58 /*
59  *
60  */
61 #define MEM_TRACK_ALLOC(__hdr,__id) (__id*)mem_track_alloc(__hdr,sizeof(__id))
62
63 #define MEM_TRACK_ALLOC_LIST(__hdr,__id,__n) (__id**)mem_track_alloc(__hdr,sizeof(__id)*__n)
64
65 #define MEM_TRACK_ALLOC_PTR_LIST(__hdr,__id,__n) (__id**)mem_track_alloc(__hdr,sizeof(__id*)*__n)
66
67 #define MEM_TRACK_ALLOC_BUFFER(__hdr,__id,__n) (__id*)mem_track_alloc(__hdr,sizeof(__id)*__n)
68
69 #define MEM_TRACK_ALLOC_INIT(__val, __hdr,__id,__init) __id* __val=MEM_TRACK_ALLOC(__hdr,__id); *__val=(__id)__init
70
71 #ifdef __cplusplus
72 }
73 #endif
74
75 #endif