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