xref: /aoo41x/main/sal/rtl/source/alloc_arena.h (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #ifndef INCLUDED_RTL_ALLOC_ARENA_H
29*cdf0e10cSrcweir #define INCLUDED_RTL_ALLOC_ARENA_H
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "sal/types.h"
32*cdf0e10cSrcweir #include "rtl/alloc.h"
33*cdf0e10cSrcweir #include "alloc_impl.h"
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir #ifdef __cplusplus
36*cdf0e10cSrcweir extern "C" {
37*cdf0e10cSrcweir #endif
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir /** rtl_arena_stat_type
40*cdf0e10cSrcweir  *  @internal
41*cdf0e10cSrcweir  */
42*cdf0e10cSrcweir typedef struct rtl_arena_stat_st rtl_arena_stat_type;
43*cdf0e10cSrcweir struct rtl_arena_stat_st
44*cdf0e10cSrcweir {
45*cdf0e10cSrcweir 	sal_uInt64 m_alloc;
46*cdf0e10cSrcweir 	sal_uInt64 m_free;
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir 	sal_Size   m_mem_total;
49*cdf0e10cSrcweir 	sal_Size   m_mem_alloc;
50*cdf0e10cSrcweir };
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir /** rtl_arena_segment_type
54*cdf0e10cSrcweir  *  @internal
55*cdf0e10cSrcweir  */
56*cdf0e10cSrcweir #define RTL_ARENA_SEGMENT_TYPE_HEAD ((sal_Size)(0x01))
57*cdf0e10cSrcweir #define RTL_ARENA_SEGMENT_TYPE_SPAN ((sal_Size)(0x02))
58*cdf0e10cSrcweir #define RTL_ARENA_SEGMENT_TYPE_FREE ((sal_Size)(0x04))
59*cdf0e10cSrcweir #define RTL_ARENA_SEGMENT_TYPE_USED ((sal_Size)(0x08))
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir typedef struct rtl_arena_segment_st rtl_arena_segment_type;
62*cdf0e10cSrcweir struct rtl_arena_segment_st
63*cdf0e10cSrcweir {
64*cdf0e10cSrcweir 	/* segment list linkage */
65*cdf0e10cSrcweir 	rtl_arena_segment_type * m_snext;
66*cdf0e10cSrcweir 	rtl_arena_segment_type * m_sprev;
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir 	/* free/used list linkage */
69*cdf0e10cSrcweir 	rtl_arena_segment_type * m_fnext;
70*cdf0e10cSrcweir 	rtl_arena_segment_type * m_fprev;
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir 	/* segment description */
73*cdf0e10cSrcweir 	sal_uIntPtr         m_addr;
74*cdf0e10cSrcweir 	sal_Size            m_size;
75*cdf0e10cSrcweir 	sal_Size            m_type;
76*cdf0e10cSrcweir };
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir /** rtl_arena_type
80*cdf0e10cSrcweir  *  @internal
81*cdf0e10cSrcweir  */
82*cdf0e10cSrcweir #define RTL_ARENA_FREELIST_SIZE (sizeof(void*) * 8)
83*cdf0e10cSrcweir #define RTL_ARENA_HASH_SIZE     64
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir #define RTL_ARENA_FLAG_RESCALE  1 /* within hash rescale operation */
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir struct rtl_arena_st
88*cdf0e10cSrcweir {
89*cdf0e10cSrcweir 	/* linkage */
90*cdf0e10cSrcweir 	rtl_arena_type *          m_arena_next;
91*cdf0e10cSrcweir 	rtl_arena_type *          m_arena_prev;
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir 	/* properties */
94*cdf0e10cSrcweir 	char                      m_name[RTL_ARENA_NAME_LENGTH + 1];
95*cdf0e10cSrcweir 	long                      m_flags;
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir 	rtl_memory_lock_type      m_lock;
98*cdf0e10cSrcweir 	rtl_arena_stat_type       m_stats;
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir 	rtl_arena_type *          m_source_arena;
101*cdf0e10cSrcweir 	void * (SAL_CALL * m_source_alloc)(rtl_arena_type *, sal_Size *);
102*cdf0e10cSrcweir 	void   (SAL_CALL * m_source_free) (rtl_arena_type *, void *, sal_Size);
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir 	sal_Size                  m_quantum;
105*cdf0e10cSrcweir 	sal_Size                  m_quantum_shift; /* log2(m_quantum) */
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir 	rtl_arena_segment_type    m_segment_reserve_span_head;
108*cdf0e10cSrcweir 	rtl_arena_segment_type    m_segment_reserve_head;
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir 	rtl_arena_segment_type    m_segment_head;
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir 	rtl_arena_segment_type    m_freelist_head[RTL_ARENA_FREELIST_SIZE];
113*cdf0e10cSrcweir 	sal_Size                  m_freelist_bitmap;
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir 	rtl_arena_segment_type ** m_hash_table;
116*cdf0e10cSrcweir 	rtl_arena_segment_type *  m_hash_table_0[RTL_ARENA_HASH_SIZE];
117*cdf0e10cSrcweir 	sal_Size                  m_hash_size;  /* m_hash_mask + 1   */
118*cdf0e10cSrcweir 	sal_Size                  m_hash_shift; /* log2(m_hash_size) */
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir 	sal_Size                  m_qcache_max;
121*cdf0e10cSrcweir 	rtl_cache_type **         m_qcache_ptr;
122*cdf0e10cSrcweir };
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir 
125*cdf0e10cSrcweir /** gp_default_arena
126*cdf0e10cSrcweir  *  default arena with pagesize quantum
127*cdf0e10cSrcweir  *
128*cdf0e10cSrcweir  *  @internal
129*cdf0e10cSrcweir  */
130*cdf0e10cSrcweir extern rtl_arena_type * gp_default_arena;
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir #ifdef __cplusplus
134*cdf0e10cSrcweir }
135*cdf0e10cSrcweir #endif
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir #endif /* INCLUDED_RTL_ALLOC_ARENA_H */
138