xref: /aoo42x/main/sal/rtl/source/alloc_arena.h (revision 514f4c20)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef INCLUDED_RTL_ALLOC_ARENA_H
25 #define INCLUDED_RTL_ALLOC_ARENA_H
26 
27 #include "sal/types.h"
28 #include "rtl/alloc.h"
29 #include "alloc_impl.h"
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 /** rtl_arena_stat_type
36  *  @internal
37  */
38 typedef struct rtl_arena_stat_st rtl_arena_stat_type;
39 struct rtl_arena_stat_st
40 {
41 	sal_uInt64 m_alloc;
42 	sal_uInt64 m_free;
43 
44 	sal_Size   m_mem_total;
45 	sal_Size   m_mem_alloc;
46 };
47 
48 
49 /** rtl_arena_segment_type
50  *  @internal
51  */
52 #define RTL_ARENA_SEGMENT_TYPE_HEAD ((sal_Size)(0x01))
53 #define RTL_ARENA_SEGMENT_TYPE_SPAN ((sal_Size)(0x02))
54 #define RTL_ARENA_SEGMENT_TYPE_FREE ((sal_Size)(0x04))
55 #define RTL_ARENA_SEGMENT_TYPE_USED ((sal_Size)(0x08))
56 
57 typedef struct rtl_arena_segment_st rtl_arena_segment_type;
58 struct rtl_arena_segment_st
59 {
60 	/* segment list linkage */
61 	rtl_arena_segment_type * m_snext;
62 	rtl_arena_segment_type * m_sprev;
63 
64 	/* free/used list linkage */
65 	rtl_arena_segment_type * m_fnext;
66 	rtl_arena_segment_type * m_fprev;
67 
68 	/* segment description */
69 	sal_uIntPtr         m_addr;
70 	sal_Size            m_size;
71 	sal_Size            m_type;
72 };
73 
74 
75 /** rtl_arena_type
76  *  @internal
77  */
78 #define RTL_ARENA_FREELIST_SIZE (sizeof(void*) * 8)
79 #define RTL_ARENA_HASH_SIZE     64
80 
81 #define RTL_ARENA_FLAG_RESCALE  1 /* within hash rescale operation */
82 
83 struct rtl_arena_st
84 {
85 	/* linkage */
86 	rtl_arena_type *          m_arena_next;
87 	rtl_arena_type *          m_arena_prev;
88 
89 	/* properties */
90 	char                      m_name[RTL_ARENA_NAME_LENGTH + 1];
91 	long                      m_flags;
92 
93 	rtl_memory_lock_type      m_lock;
94 	rtl_arena_stat_type       m_stats;
95 
96 	rtl_arena_type *          m_source_arena;
97 	void * (SAL_CALL * m_source_alloc)(rtl_arena_type *, sal_Size *);
98 	void   (SAL_CALL * m_source_free) (rtl_arena_type *, void *, sal_Size);
99 
100 	sal_Size                  m_quantum;
101 	sal_Size                  m_quantum_shift; /* log2(m_quantum) */
102 
103 	rtl_arena_segment_type    m_segment_reserve_span_head;
104 	rtl_arena_segment_type    m_segment_reserve_head;
105 
106 	rtl_arena_segment_type    m_segment_head;
107 
108 	rtl_arena_segment_type    m_freelist_head[RTL_ARENA_FREELIST_SIZE];
109 	sal_Size                  m_freelist_bitmap;
110 
111 	rtl_arena_segment_type ** m_hash_table;
112 	rtl_arena_segment_type *  m_hash_table_0[RTL_ARENA_HASH_SIZE];
113 	sal_Size                  m_hash_size;  /* m_hash_mask + 1   */
114 	sal_Size                  m_hash_shift; /* log2(m_hash_size) */
115 
116 	sal_Size                  m_qcache_max;
117 	rtl_cache_type **         m_qcache_ptr;
118 };
119 
120 
121 /** gp_default_arena
122  *  default arena with pagesize quantum
123  *
124  *  @internal
125  */
126 extern rtl_arena_type * gp_default_arena;
127 
128 
129 #ifdef __cplusplus
130 }
131 #endif
132 
133 #endif /* INCLUDED_RTL_ALLOC_ARENA_H */
134