1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: alloc_cache.h,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef INCLUDED_RTL_ALLOC_CACHE_H
32 #define INCLUDED_RTL_ALLOC_CACHE_H
34 #include "sal/types.h"
35 #include "rtl/alloc.h"
36 #include "alloc_impl.h"
42 /** rtl_cache_stat_type
45 typedef struct rtl_cache_stat_st rtl_cache_stat_type
;
46 struct rtl_cache_stat_st
56 /** rtl_cache_bufctl_type
59 typedef struct rtl_cache_bufctl_st rtl_cache_bufctl_type
;
60 struct rtl_cache_bufctl_st
62 rtl_cache_bufctl_type
* m_next
; /* linkage */
64 sal_uIntPtr m_addr
; /* buffer address */
65 sal_uIntPtr m_slab
; /* parent slab address */
69 /** rtl_cache_slab_type
72 typedef struct rtl_cache_slab_st rtl_cache_slab_type
;
73 struct rtl_cache_slab_st
75 rtl_cache_slab_type
* m_slab_next
; /* slab linkage */
76 rtl_cache_slab_type
* m_slab_prev
; /* slab linkage */
78 sal_Size m_ntypes
; /* number of buffers used */
79 sal_uIntPtr m_data
; /* buffer start addr */
81 sal_uIntPtr m_bp
; /* free buffer linkage 'base pointer' */
82 rtl_cache_bufctl_type
* m_sp
; /* free buffer linkage 'stack pointer' */
86 /** rtl_cache_magazine_type
89 #define RTL_CACHE_MAGAZINE_SIZE 61
91 typedef struct rtl_cache_magazine_st rtl_cache_magazine_type
;
92 struct rtl_cache_magazine_st
94 rtl_cache_magazine_type
* m_mag_next
; /* depot linkage */
99 void * m_objects
[RTL_CACHE_MAGAZINE_SIZE
];
103 /** rtl_cache_depot_type
106 typedef struct rtl_cache_depot_st rtl_cache_depot_type
;
107 struct rtl_cache_depot_st
110 rtl_cache_magazine_type
* m_mag_next
; /* linkage */
111 sal_Size m_mag_count
; /* count */
113 /* working set parameters */
122 #define RTL_CACHE_HASH_SIZE 8
124 #define RTL_CACHE_FEATURE_HASH 1
125 #define RTL_CACHE_FEATURE_BULKDESTROY 2
126 #define RTL_CACHE_FEATURE_RESCALE 4 /* within hash rescale operation */
131 rtl_cache_type
* m_cache_next
;
132 rtl_cache_type
* m_cache_prev
;
135 char m_name
[RTL_CACHE_NAME_LENGTH
+ 1];
138 sal_Size m_type_size
; /* const */
139 sal_Size m_type_align
; /* const */
140 sal_Size m_type_shift
; /* log2(m_type_size); const */
142 int (SAL_CALL
* m_constructor
)(void * obj
, void * userarg
); /* const */
143 void (SAL_CALL
* m_destructor
) (void * obj
, void * userarg
); /* const */
144 void (SAL_CALL
* m_reclaim
) (void * userarg
); /* const */
148 rtl_memory_lock_type m_slab_lock
;
149 rtl_cache_stat_type m_slab_stats
;
151 rtl_arena_type
* m_source
; /* slab supplier; const */
152 sal_Size m_slab_size
; /* const */
153 sal_Size m_ntypes
; /* number of buffers per slab; const */
154 sal_Size m_ncolor
; /* next slab color */
155 sal_Size m_ncolor_max
; /* max. slab color */
157 rtl_cache_slab_type m_free_head
;
158 rtl_cache_slab_type m_used_head
;
160 rtl_cache_bufctl_type
** m_hash_table
;
161 rtl_cache_bufctl_type
* m_hash_table_0
[RTL_CACHE_HASH_SIZE
];
162 sal_Size m_hash_size
; /* m_hash_mask + 1 */
163 sal_Size m_hash_shift
; /* log2(m_hash_size) */
166 rtl_memory_lock_type m_depot_lock
;
168 rtl_cache_depot_type m_depot_empty
;
169 rtl_cache_depot_type m_depot_full
;
171 rtl_cache_type
* m_magazine_cache
; /* magazine supplier; const */
174 rtl_cache_magazine_type
* m_cpu_curr
;
175 rtl_cache_magazine_type
* m_cpu_prev
;
177 rtl_cache_stat_type m_cpu_stats
;
185 #endif /* INCLUDED_RTL_ALLOC_CACHE_H */