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