xref: /aoo41x/main/sal/rtl/source/alloc_cache.h (revision cdf0e10c)
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_CACHE_H
29 #define INCLUDED_RTL_ALLOC_CACHE_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_cache_stat_type
40  *  @internal
41  */
42 typedef struct rtl_cache_stat_st rtl_cache_stat_type;
43 struct rtl_cache_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_cache_bufctl_type
54  *  @internal
55  */
56 typedef struct rtl_cache_bufctl_st rtl_cache_bufctl_type;
57 struct rtl_cache_bufctl_st
58 {
59 	rtl_cache_bufctl_type * m_next; /* linkage */
60 
61 	sal_uIntPtr             m_addr; /* buffer address  */
62 	sal_uIntPtr             m_slab; /* parent slab address */
63 };
64 
65 
66 /** rtl_cache_slab_type
67  *  @internal
68  */
69 typedef struct rtl_cache_slab_st rtl_cache_slab_type;
70 struct rtl_cache_slab_st
71 {
72 	rtl_cache_slab_type *   m_slab_next; /* slab linkage */
73 	rtl_cache_slab_type *   m_slab_prev; /* slab linkage */
74 
75 	sal_Size                m_ntypes;    /* number of buffers used */
76 	sal_uIntPtr             m_data;      /* buffer start addr */
77 
78 	sal_uIntPtr             m_bp;        /* free buffer linkage 'base pointer'  */
79 	rtl_cache_bufctl_type * m_sp;        /* free buffer linkage 'stack pointer' */
80 };
81 
82 
83 /** rtl_cache_magazine_type
84  *  @internal
85  */
86 #define RTL_CACHE_MAGAZINE_SIZE 61
87 
88 typedef struct rtl_cache_magazine_st rtl_cache_magazine_type;
89 struct rtl_cache_magazine_st
90 {
91 	rtl_cache_magazine_type * m_mag_next; /* depot linkage */
92 
93 	sal_Size                  m_mag_size;
94 	sal_Size                  m_mag_used;
95 
96 	void *                    m_objects[RTL_CACHE_MAGAZINE_SIZE];
97 };
98 
99 
100 /** rtl_cache_depot_type
101  *  @internal
102  */
103 typedef struct rtl_cache_depot_st rtl_cache_depot_type;
104 struct rtl_cache_depot_st
105 {
106 	/* magazine list */
107 	rtl_cache_magazine_type * m_mag_next;  /* linkage */
108 	sal_Size                  m_mag_count; /* count */
109 
110 	/* working set parameters */
111 	sal_Size                  m_curr_min;
112 	sal_Size                  m_prev_min;
113 };
114 
115 
116 /** rtl_cache_type
117  *  @internal
118  */
119 #define RTL_CACHE_HASH_SIZE        8
120 
121 #define RTL_CACHE_FEATURE_HASH        1
122 #define RTL_CACHE_FEATURE_BULKDESTROY 2
123 #define RTL_CACHE_FEATURE_RESCALE     4 /* within hash rescale operation */
124 
125 struct rtl_cache_st
126 {
127 	/* linkage */
128 	rtl_cache_type *          m_cache_next;
129 	rtl_cache_type *          m_cache_prev;
130 
131 	/* properties */
132 	char                      m_name[RTL_CACHE_NAME_LENGTH + 1];
133 	long                      m_features;
134 
135 	sal_Size                  m_type_size;   /* const */
136 	sal_Size                  m_type_align;  /* const */
137 	sal_Size                  m_type_shift;  /* log2(m_type_size); const */
138 
139 	int  (SAL_CALL * m_constructor)(void * obj, void * userarg); /* const */
140 	void (SAL_CALL * m_destructor) (void * obj, void * userarg); /* const */
141 	void (SAL_CALL * m_reclaim)    (void * userarg);             /* const */
142 	void *                    m_userarg;
143 
144 	/* slab layer */
145 	rtl_memory_lock_type      m_slab_lock;
146 	rtl_cache_stat_type       m_slab_stats;
147 
148 	rtl_arena_type *          m_source;     /* slab supplier; const */
149 	sal_Size                  m_slab_size;  /* const */
150 	sal_Size                  m_ntypes;     /* number of buffers per slab; const */
151 	sal_Size                  m_ncolor;     /* next slab color */
152 	sal_Size                  m_ncolor_max; /* max. slab color */
153 
154 	rtl_cache_slab_type       m_free_head;
155 	rtl_cache_slab_type       m_used_head;
156 
157 	rtl_cache_bufctl_type **  m_hash_table;
158 	rtl_cache_bufctl_type *   m_hash_table_0[RTL_CACHE_HASH_SIZE];
159 	sal_Size                  m_hash_size;  /* m_hash_mask + 1   */
160 	sal_Size                  m_hash_shift; /* log2(m_hash_size) */
161 
162 	/* depot layer */
163 	rtl_memory_lock_type      m_depot_lock;
164 
165 	rtl_cache_depot_type      m_depot_empty;
166 	rtl_cache_depot_type      m_depot_full;
167 
168 	rtl_cache_type *          m_magazine_cache; /* magazine supplier; const */
169 
170 	/* cpu layer */
171 	rtl_cache_magazine_type * m_cpu_curr;
172 	rtl_cache_magazine_type * m_cpu_prev;
173 
174 	rtl_cache_stat_type       m_cpu_stats;
175 };
176 
177 
178 #ifdef __cplusplus
179 }
180 #endif
181 
182 #endif /* INCLUDED_RTL_ALLOC_CACHE_H */
183