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