Changeset 854 in svn


Ignore:
Timestamp:
2012-03-28T10:48:20+02:00 (3 years ago)
Author:
Xuefer
Message:

remove type/cache/hvalue from cached copy to reduce memory usage a little bit

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/processor/head.m4

    r851 r854  
    389389dnl ================ export API
    390390define(`DEFINE_STORE_API', `
    391 /* export: $1 *xc_processor_store_$1($1 *src TSRMLS_DC); :export {{{ */
    392 $1 *xc_processor_store_$1($1 *src TSRMLS_DC) {
     391/* export: $1 *xc_processor_store_$1(xc_cache_t *cache, $1 *src TSRMLS_DC); :export {{{ */
     392$1 *xc_processor_store_$1(xc_cache_t *cache, $1 *src TSRMLS_DC) {
    393393    $1 *dst;
    394394    xc_processor_t processor;
     
    396396    memset(&processor, 0, sizeof(processor));
    397397    processor.reference = 1;
    398     processor.cache = src->ifelse(`$1', `xc_entry_php_t', entry.)cache;
     398    processor.cache = cache;
    399399
    400400    IFASSERT(`xc_stack_init(&processor.allocsizes);')
     
    418418    src->ifelse(`$1', `xc_entry_php_t', entry.)size = processor.size;
    419419    ifelse(
    420         `$1', `xc_entry_t', `src->data.var.have_references = processor.have_references;',
     420        `$1', `xc_entry_var_t', `src->have_references = processor.have_references;',
    421421        `$1', `xc_entry_data_php_t', `src->have_references = processor.have_references;'
    422422    )
  • trunk/processor/processor.m4

    r851 r854  
    10671067    ')
    10681068
    1069     PROCESS(xc_hash_value_t, hvalue)
    10701069    /* skip */
    10711070    DONE(next)
    1072     COPY(cache)
     1071    PROCESS(xc_hash_value_t, hvalue)
    10731072    PROCESS(xc_md5sum_t, md5)
    10741073    PROCESS(zend_ulong, refcount)
     
    11191118')
    11201119dnl }}}
    1121 DEF_STRUCT_P_FUNC(`xc_entry_data_var_t', , `dnl {{{
    1122     IFDPRINT(`INDENT()`'fprintf(stderr, "zval:value");')
    1123     STRUCT_P_EX(zval_ptr, dst->value, src->value, `value', `', `&')
    1124     PROCESS(zend_bool, have_references)
    1125     DONE(value)
    1126 ')
    1127 dnl }}}
    11281120DEF_STRUCT_P_FUNC(`xc_entry_t', , `dnl {{{
    1129     PROCESS(xc_hash_value_t, hvalue)
    11301121    /* skip */
    11311122    DONE(next)
    1132     COPY(cache)
    1133     PROCESS(xc_entry_type_t, type)
    11341123    PROCESS(size_t, size)
    11351124
     
    11641153    DONE(name)
    11651154    dnl }}}
    1166 
    1167     dnl {{{ data
    1168     DISABLECHECK(`
    1169         switch (src->type) {
    1170         case XC_TYPE_PHP:
    1171             IFCALCCOPY(`COPY(data.php)', `STRUCT_P(xc_entry_data_php_t, data.php)')
    1172             break;
    1173 
    1174         case XC_TYPE_VAR:
    1175             STRUCT(xc_entry_data_var_t, data.var)
    1176             break;
    1177 
    1178         default:
    1179             assert(0);
    1180         }
    1181     ')
    1182     DONE(data)
    1183     dnl }}}
    11841155')
    11851156dnl }}}
    11861157DEF_STRUCT_P_FUNC(`xc_entry_php_t', , `dnl {{{
    11871158    STRUCT(xc_entry_t, entry)
     1159    IFCALCCOPY(`COPY(php)', `STRUCT_P(xc_entry_data_php_t, php)')
    11881160
    11891161    IFSTORE(`dst->refcount = 0; DONE(refcount)', `PROCESS(long, refcount)')
     
    11941166#endif
    11951167
    1196     if (src->entry.type == XC_TYPE_PHP) {
    1197         PROCESS(int, filepath_len)
    1198         IFRESTORE(`COPY(filepath)', `PROC_STRING_L(filepath, filepath_len)')
    1199         PROCESS(int, dirpath_len)
    1200         IFRESTORE(`COPY(dirpath)', `PROC_STRING_L(dirpath, dirpath_len)')
     1168    PROCESS(int, filepath_len)
     1169    IFRESTORE(`COPY(filepath)', `PROC_STRING_L(filepath, filepath_len)')
     1170    PROCESS(int, dirpath_len)
     1171    IFRESTORE(`COPY(dirpath)', `PROC_STRING_L(dirpath, dirpath_len)')
    12011172#ifdef IS_UNICODE
    1202         PROCESS(int, ufilepath_len)
    1203         IFRESTORE(`COPY(ufilepath)', `PROC_USTRING_L(ufilepath, ufilepath_len)')
    1204         PROCESS(int, udirpath_len)
    1205         IFRESTORE(`COPY(udirpath)', `PROC_USTRING_L(udirpath, udirpath_len)')
    1206 #endif
    1207     }
    1208     else {
    1209         DONE(filepath_len)
    1210         DONE(filepath)
    1211         DONE(dirpath_len)
    1212         DONE(dirpath)
    1213 #ifdef IS_UNICODE
    1214         DONE(ufilepath_len)
    1215         DONE(ufilepath)
    1216         DONE(udirpath_len)
    1217         DONE(udirpath)
    1218 #endif
    1219     }
     1173    PROCESS(int, ufilepath_len)
     1174    IFRESTORE(`COPY(ufilepath)', `PROC_USTRING_L(ufilepath, ufilepath_len)')
     1175    PROCESS(int, udirpath_len)
     1176    IFRESTORE(`COPY(udirpath)', `PROC_USTRING_L(udirpath, udirpath_len)')
     1177#endif
     1178')
     1179dnl }}}
     1180DEF_STRUCT_P_FUNC(`xc_entry_var_t', , `dnl {{{
     1181    STRUCT(xc_entry_t, entry)
     1182
     1183    IFDPRINT(`INDENT()`'fprintf(stderr, "zval:value");')
     1184    STRUCT_P_EX(zval_ptr, dst->value, src->value, `value', `', `&')
     1185    PROCESS(zend_bool, have_references)
     1186    DONE(value)
    12201187')
    12211188dnl }}}
  • trunk/xcache.c

    r851 r854  
    113113ZEND_DLEXPORT zend_extension zend_extension_entry;
    114114ZEND_DECLARE_MODULE_GLOBALS(xcache);
     115
     116typedef enum { XC_TYPE_PHP, XC_TYPE_VAR } xc_entry_type_t;
    115117/* }}} */
    116118
    117119/* any function in *_dmz is only safe be called within locked(single thread) area */
    118120
    119 static void xc_php_add_dmz(xc_entry_data_php_t *php) /* {{{ */
    120 {
    121     xc_entry_data_php_t **head = &(php->cache->phps[php->hvalue]);
     121static void xc_php_add_dmz(xc_cache_t *cache, xc_entry_data_php_t *php) /* {{{ */
     122{
     123    xc_entry_data_php_t **head = &(cache->phps[php->hvalue]);
    122124    php->next = *head;
    123125    *head = php;
    124     php->cache->phps_count ++;
    125 }
    126 /* }}} */
    127 static xc_entry_data_php_t *xc_php_store_dmz(xc_entry_data_php_t *php TSRMLS_DC) /* {{{ */
     126    cache->phps_count ++;
     127}
     128/* }}} */
     129static xc_entry_data_php_t *xc_php_store_dmz(xc_cache_t *cache, xc_entry_data_php_t *php TSRMLS_DC) /* {{{ */
    128130{
    129131    xc_entry_data_php_t *stored_php;
     
    131133    php->hits     = 0;
    132134    php->refcount = 0;
    133     stored_php = xc_processor_store_xc_entry_data_php_t(php TSRMLS_CC);
     135    stored_php = xc_processor_store_xc_entry_data_php_t(cache, php TSRMLS_CC);
    134136    if (stored_php) {
    135         xc_php_add_dmz(stored_php);
     137        xc_php_add_dmz(cache, stored_php);
    136138        return stored_php;
    137139    }
    138140    else {
    139         php->cache->ooms ++;
     141        cache->ooms ++;
    140142        return NULL;
    141143    }
    142144}
    143145/* }}} */
    144 static xc_entry_data_php_t *xc_php_find_dmz(xc_entry_data_php_t *php TSRMLS_DC) /* {{{ */
     146static xc_entry_data_php_t *xc_php_find_dmz(xc_cache_t *cache, xc_entry_data_php_t *php TSRMLS_DC) /* {{{ */
    145147{
    146148    xc_entry_data_php_t *p;
    147     for (p = php->cache->phps[php->hvalue]; p; p = (xc_entry_data_php_t *) p->next) {
     149    for (p = cache->phps[php->hvalue]; p; p = (xc_entry_data_php_t *) p->next) {
    148150        if (memcmp(&php->md5.digest, &p->md5.digest, sizeof(php->md5.digest)) == 0) {
    149151            p->hits ++;
     
    154156}
    155157/* }}} */
    156 static void xc_php_free_dmz(xc_entry_data_php_t *php) /* {{{ */
    157 {
    158     php->cache->mem->handlers->free(php->cache->mem, (xc_entry_data_php_t *)php);
     158static void xc_php_free_dmz(xc_cache_t *cache, xc_entry_data_php_t *php) /* {{{ */
     159{
     160    cache->mem->handlers->free(cache->mem, (xc_entry_data_php_t *)php);
    159161}
    160162/* }}} */
     
    164166}
    165167/* }}} */
    166 static void xc_php_release_dmz(xc_entry_data_php_t *php) /* {{{ */
     168static void xc_php_release_dmz(xc_cache_t *cache, xc_entry_data_php_t *php) /* {{{ */
    167169{
    168170    if (-- php->refcount == 0) {
    169         xc_entry_data_php_t **pp = &(php->cache->phps[php->hvalue]);
     171        xc_entry_data_php_t **pp = &(cache->phps[php->hvalue]);
    170172        xc_entry_data_php_t *p;
    171173        for (p = *pp; p; pp = &(p->next), p = p->next) {
     
    173175                /* unlink */
    174176                *pp = p->next;
    175                 xc_php_free_dmz(php);
     177                xc_php_free_dmz(cache, php);
    176178                return;
    177179            }
     
    182184/* }}} */
    183185
    184 static inline int xc_entry_equal_dmz(const xc_entry_t *entry1, const xc_entry_t *entry2) /* {{{ */
     186static inline int xc_entry_equal_dmz(xc_entry_type_t type, const xc_entry_t *entry1, const xc_entry_t *entry2) /* {{{ */
    185187{
    186188    /* this function isn't required but can be in dmz */
    187 
    188     if (entry1->type != entry2->type) {
    189         return 0;
    190     }
    191     switch (entry1->type) {
     189    switch (type) {
    192190        case XC_TYPE_PHP:
    193191#ifdef HAVE_INODE
     
    225223}
    226224/* }}} */
    227 static inline int xc_entry_has_prefix_dmz(xc_entry_t *entry, zval *prefix) /* {{{ */
     225static inline int xc_entry_has_prefix_dmz(xc_entry_type_t type, xc_entry_t *entry, zval *prefix) /* {{{ */
    228226{
    229227    /* this function isn't required but can be in dmz */
    230228
    231     switch (entry->type) {
    232         case XC_TYPE_PHP:
    233         case XC_TYPE_VAR:
    234             do {
    235229#ifdef IS_UNICODE
    236                 if (entry->name_type != prefix->type) {
    237                     return 0;
    238                 }
    239 
    240                 if (entry->name_type == IS_UNICODE) {
    241                     if (entry->name.ustr.len < Z_USTRLEN_P(prefix)) {
    242                         return 0;
    243                     }
    244                     return memcmp(entry->name.ustr.val, Z_USTRVAL_P(prefix), Z_USTRLEN_P(prefix) * sizeof(UChar)) == 0;
    245                 }
    246 #endif
    247                 if (prefix->type != IS_STRING) {
    248                     return 0;
    249                 }
    250 
    251                 if (entry->name.str.len < Z_STRLEN_P(prefix)) {
    252                     return 0;
    253                 }
    254 
    255                 return memcmp(entry->name.str.val, Z_STRVAL_P(prefix), Z_STRLEN_P(prefix)) == 0;
    256 
    257             } while(0);
    258         default:
    259             assert(0);
    260     }
    261     return 0;
    262 }
    263 /* }}} */
    264 static void xc_entry_add_dmz(xc_entry_t *xce) /* {{{ */
    265 {
    266     xc_entry_t **head = &(xce->cache->entries[xce->hvalue]);
     230    if (entry->name_type != prefix->type) {
     231        return 0;
     232    }
     233
     234    if (entry->name_type == IS_UNICODE) {
     235        if (entry->name.ustr.len < Z_USTRLEN_P(prefix)) {
     236            return 0;
     237        }
     238        return memcmp(entry->name.ustr.val, Z_USTRVAL_P(prefix), Z_USTRLEN_P(prefix) * sizeof(UChar)) == 0;
     239    }
     240#endif
     241    if (prefix->type != IS_STRING) {
     242        return 0;
     243    }
     244
     245    if (entry->name.str.len < Z_STRLEN_P(prefix)) {
     246        return 0;
     247    }
     248
     249    return memcmp(entry->name.str.val, Z_STRVAL_P(prefix), Z_STRLEN_P(prefix)) == 0;
     250}
     251/* }}} */
     252static void xc_entry_add_dmz(xc_cache_t *cache, xc_hash_value_t entryslotid, xc_entry_t *xce) /* {{{ */
     253{
     254    xc_entry_t **head = &(cache->entries[entryslotid]);
    267255    xce->next = *head;
    268256    *head = xce;
    269     xce->cache->entries_count ++;
    270 }
    271 /* }}} */
    272 static xc_entry_t *xc_entry_store_dmz(xc_entry_t *xce TSRMLS_DC) /* {{{ */
     257    cache->entries_count ++;
     258}
     259/* }}} */
     260static xc_entry_t *xc_entry_store_dmz(xc_entry_type_t type, xc_cache_t *cache, xc_hash_value_t entryslotid, xc_entry_t *xce TSRMLS_DC) /* {{{ */
    273261{
    274262    xc_entry_t *stored_xce;
     
    277265    xce->ctime = XG(request_time);
    278266    xce->atime = XG(request_time);
    279     stored_xce = xce->type == XC_TYPE_PHP
    280         ? (xc_entry_t *) xc_processor_store_xc_entry_php_t((xc_entry_php_t *) xce TSRMLS_CC)
    281         : xc_processor_store_xc_entry_t(xce TSRMLS_CC);
     267    stored_xce = type == XC_TYPE_PHP
     268        ? (xc_entry_t *) xc_processor_store_xc_entry_php_t(cache, (xc_entry_php_t *) xce TSRMLS_CC)
     269        : xc_processor_store_xc_entry_t(cache, xce TSRMLS_CC);
    282270    if (stored_xce) {
    283         xc_entry_add_dmz(stored_xce);
     271        xc_entry_add_dmz(cache, entryslotid, stored_xce);
    284272        return stored_xce;
    285273    }
    286274    else {
    287         xce->cache->ooms ++;
     275        cache->ooms ++;
    288276        return NULL;
    289277    }
    290278}
    291279/* }}} */
    292 static xc_entry_php_t *xc_entry_php_store_dmz(xc_entry_php_t *xce TSRMLS_DC) /* {{{ */
    293 {
    294     return (xc_entry_php_t *) xc_entry_store_dmz((xc_entry_t *) xce TSRMLS_CC);
    295 }
    296 /* }}} */
    297 static void xc_entry_free_real_dmz(volatile xc_entry_t *xce) /* {{{ */
    298 {
    299     if (xce->type == XC_TYPE_PHP) {
    300         xc_php_release_dmz(xce->data.php);
    301     }
    302     xce->cache->mem->handlers->free(xce->cache->mem, (xc_entry_t *)xce);
    303 }
    304 /* }}} */
    305 static void xc_entry_free_dmz(xc_entry_t *xce TSRMLS_DC) /* {{{ */
    306 {
    307     xce->cache->entries_count --;
    308     if ((xce->type == XC_TYPE_PHP ? ((xc_entry_php_t *) xce)->refcount : 0) == 0) {
    309         xc_entry_free_real_dmz(xce);
     280static xc_entry_php_t *xc_entry_php_store_dmz(xc_cache_t *cache, xc_hash_value_t entryslotid, xc_entry_php_t *xce TSRMLS_DC) /* {{{ */
     281{
     282    return (xc_entry_php_t *) xc_entry_store_dmz(XC_TYPE_PHP, cache, entryslotid, (xc_entry_t *) xce TSRMLS_CC);
     283}
     284/* }}} */
     285static void xc_entry_free_real_dmz(xc_entry_type_t type, xc_cache_t *cache, volatile xc_entry_t *xce) /* {{{ */
     286{
     287    if (type == XC_TYPE_PHP) {
     288        xc_php_release_dmz(cache, ((xc_entry_php_t *) xce)->php);
     289    }
     290    cache->mem->handlers->free(cache->mem, (xc_entry_t *)xce);
     291}
     292/* }}} */
     293static void xc_entry_free_dmz(xc_entry_type_t type, xc_cache_t *cache, xc_entry_t *xce TSRMLS_DC) /* {{{ */
     294{
     295    cache->entries_count --;
     296    if ((type == XC_TYPE_PHP ? ((xc_entry_php_t *) xce)->refcount : 0) == 0) {
     297        xc_entry_free_real_dmz(type, cache, xce);
    310298    }
    311299    else {
    312         xce->next = xce->cache->deletes;
    313         xce->cache->deletes = xce;
     300        xce->next = cache->deletes;
     301        cache->deletes = xce;
    314302        xce->dtime = XG(request_time);
    315         xce->cache->deletes_count ++;
     303        cache->deletes_count ++;
    316304    }
    317305    return;
    318306}
    319307/* }}} */
    320 static void xc_entry_remove_dmz(xc_entry_t *xce TSRMLS_DC) /* {{{ */
    321 {
    322     xc_entry_t **pp = &(xce->cache->entries[xce->hvalue]);
     308static void xc_entry_remove_dmz(xc_entry_type_t type, xc_cache_t *cache, xc_hash_value_t entryslotid, xc_entry_t *xce TSRMLS_DC) /* {{{ */
     309{
     310    xc_entry_t **pp = &(cache->entries[entryslotid]);
    323311    xc_entry_t *p;
    324312    for (p = *pp; p; pp = &(p->next), p = p->next) {
    325         if (xc_entry_equal_dmz(xce, p)) {
     313        if (xc_entry_equal_dmz(type, xce, p)) {
    326314            /* unlink */
    327315            *pp = p->next;
    328             xc_entry_free_dmz(xce TSRMLS_CC);
     316            xc_entry_free_dmz(type, cache, xce TSRMLS_CC);
    329317            return;
    330318        }
     
    333321}
    334322/* }}} */
    335 static xc_entry_t *xc_entry_find_dmz(xc_entry_t *xce TSRMLS_DC) /* {{{ */
     323static xc_entry_t *xc_entry_find_dmz(xc_entry_type_t type, xc_cache_t *cache, xc_hash_value_t entryslotid, xc_entry_t *xce TSRMLS_DC) /* {{{ */
    336324{
    337325    xc_entry_t *p;
    338     for (p = xce->cache->entries[xce->hvalue]; p; p = p->next) {
    339         if (xc_entry_equal_dmz(xce, p)) {
     326    for (p = cache->entries[entryslotid]; p; p = p->next) {
     327        if (xc_entry_equal_dmz(type, xce, p)) {
    340328            zend_bool fresh;
    341             switch (p->type) {
     329            switch (type) {
    342330            case XC_TYPE_PHP:
    343331                {
    344332                    xc_entry_php_t *p_php = (xc_entry_php_t *) p;
    345333                    xc_entry_php_t *xce_php = (xc_entry_php_t *) xce;
    346                     fresh = p_php->file_mtime == xce_php->file_mtime && p->data.php->file_size == xce->data.php->file_size;
     334                    fresh = p_php->file_mtime == xce_php->file_mtime && p_php->php->file_size == xce_php->php->file_size;
    347335                    break;
    348336                }
     
    362350            }
    363351
    364             xc_entry_remove_dmz(p TSRMLS_CC);
     352            xc_entry_remove_dmz(type, cache, entryslotid, p TSRMLS_CC);
    365353            return NULL;
    366354        }
     
    369357}
    370358/* }}} */
    371 static void xc_entry_hold_php_dmz(xc_entry_php_t *xce TSRMLS_DC) /* {{{ */
     359static void xc_entry_hold_php_dmz(xc_cache_t *cache, xc_entry_php_t *xce TSRMLS_DC) /* {{{ */
    372360{
    373361    TRACE("hold %s", xce->entry.name.str.val);
    374362    xce->refcount ++;
    375     xc_stack_push(&XG(php_holds)[xce->entry.cache->cacheid], (void *)xce);
     363    xc_stack_push(&XG(php_holds)[cache->cacheid], (void *)xce);
    376364}
    377365/* }}} */
     
    437425#define XC_ENTRY_APPLY_FUNC(name) int name(xc_entry_t *entry TSRMLS_DC)
    438426typedef XC_ENTRY_APPLY_FUNC((*cache_apply_dmz_func_t));
    439 static void xc_entry_apply_dmz(xc_cache_t *cache, cache_apply_dmz_func_t apply_func TSRMLS_DC) /* {{{ */
     427static void xc_entry_apply_dmz(xc_entry_type_t type, xc_cache_t *cache, cache_apply_dmz_func_t apply_func TSRMLS_DC) /* {{{ */
    440428{
    441429    xc_entry_t *p, **pp;
     
    448436                /* unlink */
    449437                *pp = p->next;
    450                 xc_entry_free_dmz(p TSRMLS_CC);
     438                xc_entry_free_dmz(type, cache, p TSRMLS_CC);
    451439            }
    452440            else {
     
    480468}
    481469/* }}} */
    482 static void xc_gc_expires_one(xc_cache_t *cache, zend_ulong gc_interval, cache_apply_dmz_func_t apply_func TSRMLS_DC) /* {{{ */
     470static void xc_gc_expires_one(xc_entry_type_t type, xc_cache_t *cache, zend_ulong gc_interval, cache_apply_dmz_func_t apply_func TSRMLS_DC) /* {{{ */
    483471{
    484472    TRACE("interval %lu, %lu %lu", (zend_ulong) XG(request_time), (zend_ulong) cache->last_gc_expires, gc_interval);
     
    487475            if (XG(request_time) - cache->last_gc_expires >= gc_interval) {
    488476                cache->last_gc_expires = XG(request_time);
    489                 xc_entry_apply_dmz(cache, apply_func TSRMLS_CC);
     477                xc_entry_apply_dmz(type, cache, apply_func TSRMLS_CC);
    490478            }
    491479        } LEAVE_LOCK(cache);
     
    502490
    503491    for (i = 0, c = xc_php_hcache.size; i < c; i ++) {
    504         xc_gc_expires_one(xc_php_caches[i], xc_php_gc_interval, xc_gc_expires_php_entry_dmz TSRMLS_CC);
     492        xc_gc_expires_one(XC_TYPE_PHP, xc_php_caches[i], xc_php_gc_interval, xc_gc_expires_php_entry_dmz TSRMLS_CC);
    505493    }
    506494}
     
    515503
    516504    for (i = 0, c = xc_var_hcache.size; i < c; i ++) {
    517         xc_gc_expires_one(xc_var_caches[i], xc_var_gc_interval, xc_gc_expires_var_entry_dmz TSRMLS_CC);
     505        xc_gc_expires_one(XC_TYPE_VAR, xc_var_caches[i], xc_var_gc_interval, xc_gc_expires_var_entry_dmz TSRMLS_CC);
    518506    }
    519507}
     
    535523            *pp = p->next;
    536524            cache->deletes_count --;
    537             xc_entry_free_real_dmz(p);
     525            xc_entry_free_real_dmz(XC_TYPE_PHP, cache, p);
    538526        }
    539527        else {
     
    649637}
    650638/* }}} */
    651 static void xc_fillentry_dmz(const xc_entry_t *entry, int del, zval *list TSRMLS_DC) /* {{{ */
     639static void xc_fillentry_dmz(xc_entry_type_t type, const xc_entry_t *entry, xc_hash_value_t entryslotid, int del, zval *list TSRMLS_DC) /* {{{ */
    652640{
    653641    zval* ei;
    654642    const xc_entry_data_php_t *php;
    655     const xc_entry_data_var_t *var;
    656643    xc_entry_php_t *entry_php = (xc_entry_php_t *) entry;
    657644
     
    663650    add_assoc_long_ex(ei, ZEND_STRS("ctime"),    entry->ctime);
    664651    add_assoc_long_ex(ei, ZEND_STRS("atime"),    entry->atime);
    665     add_assoc_long_ex(ei, ZEND_STRS("hvalue"),   entry->hvalue);
     652    add_assoc_long_ex(ei, ZEND_STRS("hvalue"),   entryslotid);
    666653    if (del) {
    667654        add_assoc_long_ex(ei, ZEND_STRS("dtime"), entry->dtime);
     
    687674    add_assoc_stringl_ex(ei, ZEND_STRS("name"), entry->name.str.val, entry->name.str.len, 1);
    688675#endif
    689     switch (entry->type) {
     676    switch (type) {
    690677        case XC_TYPE_PHP:
    691             php = entry->data.php;
     678            php = entry_php->php;
    692679            add_assoc_long_ex(ei, ZEND_STRS("size"),          entry->size + php->size);
    693680            add_assoc_long_ex(ei, ZEND_STRS("phprefcount"),   php->refcount);
     
    710697
    711698        case XC_TYPE_VAR:
    712             var = &entry->data.var;
    713699            add_assoc_long_ex(ei, ZEND_STRS("size"),          entry->size);
    714700            break;
     
    721707}
    722708/* }}} */
    723 static void xc_filllist_dmz(xc_cache_t *cache, zval *return_value TSRMLS_DC) /* {{{ */
     709static void xc_filllist_dmz(xc_entry_type_t type, xc_cache_t *cache, zval *return_value TSRMLS_DC) /* {{{ */
    724710{
    725711    zval* list;
     
    732718    for (i = 0, c = cache->hentry->size; i < c; i ++) {
    733719        for (e = cache->entries[i]; e; e = e->next) {
    734             xc_fillentry_dmz(e, 0, list TSRMLS_CC);
     720            xc_fillentry_dmz(type, e, i, 0, list TSRMLS_CC);
    735721        }
    736722    }
     
    740726    array_init(list);
    741727    for (e = cache->deletes; e; e = e->next) {
    742         xc_fillentry_dmz(e, 1, list TSRMLS_CC);
     728        xc_fillentry_dmz(XC_TYPE_PHP, e, 0, 1, list TSRMLS_CC);
    743729    }
    744730    add_assoc_zval(return_value, "deleted_list", list);
     
    749735{
    750736    zend_uint i;
    751     xc_entry_data_php_t *p = xce->entry.data.php;
     737    xc_entry_data_php_t *p = xce->php;
    752738    zend_op_array *old_active_op_array = CG(active_op_array);
    753739#ifndef ZEND_ENGINE_2
     
    839825        TRACE("holded %d", xc_stack_count(s));
    840826        if (xc_stack_count(s)) {
    841             cache = ((xc_entry_t *)xc_stack_top(s))->cache;
     827            cache = caches[i];
    842828            ENTER_LOCK(cache) {
    843829                while (xc_stack_count(s)) {
     
    1007993/* }}} */
    1008994
    1009 static int xc_entry_init_key_php(xc_entry_php_t *xce, const char *filename TSRMLS_DC) /* {{{ */
     995static int xc_entry_init_key_php(xc_entry_hash_t *entry_hash, xc_entry_php_t *xce, const char *filename TSRMLS_DC) /* {{{ */
    1010996{
    1011997    char opened_path_buffer[MAXPATHLEN];
    1012     int cacheid;
    1013998
    1014999    if (!filename || !SG(request_info).path_translated) {
     
    10771062        xce->file_inode   = pbuf->st_ino;
    10781063#endif
    1079         xce->entry.data.php->file_size = pbuf->st_size;
     1064        xce->php->file_size = pbuf->st_size;
    10801065    }
    10811066    else { /* XG(inode) */
     
    10851070        xce->file_inode   = 0;
    10861071#endif
    1087         xce->entry.data.php->file_size = 0;
     1072        xce->php->file_size = 0;
    10881073    }
    10891074
     
    11041089    xce->entry.name.str.len = strlen(filename);
    11051090
    1106     cacheid = xc_php_hcache.size > 1 ? xc_hash_fold(xc_entry_hash_php_basename(xce TSRMLS_CC), &xc_php_hcache) : 0;
    1107     xce->entry.cache = xc_php_caches[cacheid];
    1108     xce->entry.hvalue = xc_hash_fold(xc_entry_hash_php(xce TSRMLS_CC), &xc_php_hentry);
    1109     xce->entry.type = XC_TYPE_PHP;
     1091    entry_hash->cacheslotid = xc_php_hcache.size > 1 ? xc_hash_fold(xc_entry_hash_php_basename(xce TSRMLS_CC), &xc_php_hcache) : 0;
     1092    entry_hash->entryslotid = xc_hash_fold(xc_entry_hash_php(xce TSRMLS_CC), &xc_php_hentry);
    11101093    xce->filepath  = NULL;
    11111094    xce->dirpath   = NULL;
     
    11231106}
    11241107/* }}} */
    1125 static int xc_entry_init_key_php_md5(xc_entry_data_php_t *php, xc_entry_php_t *xce TSRMLS_DC) /* {{{ */
     1108static int xc_entry_init_key_php_md5(xc_cache_t *cache, xc_entry_data_php_t *php, xc_entry_php_t *xce TSRMLS_DC) /* {{{ */
    11261109{
    11271110    unsigned char   buf[1024];
     
    11511134    }
    11521135
    1153     php->cache  = xce->entry.cache;
    1154     php->hvalue = (xc_php_hash_md5(php TSRMLS_CC) & php->cache->hphp->mask);
     1136    php->hvalue = (xc_php_hash_md5(php TSRMLS_CC) & cache->hphp->mask);
    11551137#ifdef XCACHE_DEBUG
    11561138    {
     
    17581740    TRACE("restoring %s", stored_xce->entry.name.str.val);
    17591741    xc_processor_restore_xc_entry_php_t(&xce, stored_xce TSRMLS_CC);
    1760     xc_processor_restore_xc_entry_data_php_t(stored_xce, &php, xce.entry.data.php, xc_readonly_protection TSRMLS_CC);
    1761     xce.entry.data.php = &php;
     1742    xc_processor_restore_xc_entry_data_php_t(stored_xce, &php, xce.php, xc_readonly_protection TSRMLS_CC);
     1743    xce.php = &php;
    17621744#ifdef SHOW_DPRINT
    17631745    xc_dprint(&xce, 0 TSRMLS_CC);
     
    17981780}
    17991781/* }}} */
    1800 static zend_op_array *xc_compile_file_ex(xc_entry_php_t *xce, zend_file_handle *h, int type TSRMLS_DC) /* {{{ */
     1782static zend_op_array *xc_compile_file_ex(xc_entry_hash_t *entry_hash, xc_entry_php_t *xce, zend_file_handle *h, int type TSRMLS_DC) /* {{{ */
    18011783{
    18021784    zend_op_array *op_array;
    18031785    xc_entry_php_t *stored_xce;
    18041786    xc_entry_data_php_t *stored_php;
    1805     xc_cache_t *cache = xce->entry.cache;
    18061787    zend_bool gaveup = 0;
    18071788    zend_bool catched = 0;
    18081789    zend_bool newlycompiled;
    18091790    xc_sandbox_t sandbox;
     1791    xc_cache_t *cache = xc_php_caches[entry_hash->cacheslotid];
    18101792
    18111793    /* stale clogs precheck */
     
    18181800    stored_php = NULL;
    18191801    ENTER_LOCK_EX(cache) {
    1820         stored_xce = (xc_entry_php_t *) xc_entry_find_dmz((xc_entry_t *) xce TSRMLS_CC);
     1802        stored_xce = (xc_entry_php_t *) xc_entry_find_dmz(XC_TYPE_PHP, cache, entry_hash->entryslotid, (xc_entry_t *) xce TSRMLS_CC);
    18211803        if (stored_xce) {
    18221804            xc_cache_hit_dmz(cache TSRMLS_CC);
    18231805
    18241806            TRACE("hit %s, holding", stored_xce->name.str.val);
    1825             xc_entry_hold_php_dmz(stored_xce TSRMLS_CC);
     1807            xc_entry_hold_php_dmz(cache, stored_xce TSRMLS_CC);
    18261808        }
    18271809        else {
     
    18291811            TRACE("miss %s", xce->name.str.val);
    18301812
    1831             if (xc_entry_init_key_php_md5(xce->entry.data.php, xce TSRMLS_CC) != SUCCESS) {
     1813            if (xc_entry_init_key_php_md5(cache, xce->php, xce TSRMLS_CC) != SUCCESS) {
    18321814                gaveup = 1;
    18331815                break;
    18341816            }
    18351817
    1836             stored_php = xc_php_find_dmz(xce->entry.data.php TSRMLS_CC);
     1818            stored_php = xc_php_find_dmz(cache, xce->php TSRMLS_CC);
    18371819
    18381820            /* miss but compiling */
     
    18741856        newlycompiled = 0;
    18751857        xc_entry_init_key_php_entry(xce, h->opened_path ? h->opened_path : h->filename TSRMLS_CC);
    1876         xce->entry.data.php = stored_php;
     1858        xce->php = stored_php;
    18771859    }
    18781860    else {
     
    18831865
    18841866#ifdef HAVE_XCACHE_CONSTANT
    1885         xce->entry.data.php->constinfos  = NULL;
    1886 #endif
    1887         xce->entry.data.php->funcinfos   = NULL;
    1888         xce->entry.data.php->classinfos  = NULL;
     1867        xce->php->constinfos  = NULL;
     1868#endif
     1869        xce->php->funcinfos   = NULL;
     1870        xce->php->classinfos  = NULL;
    18891871#ifdef ZEND_ENGINE_2_1
    1890         xce->entry.data.php->autoglobals = NULL;
    1891 #endif
    1892 
    1893         memset(&xce->entry.data.php->op_array_info, 0, sizeof(xce->entry.data.php->op_array_info));
     1872        xce->php->autoglobals = NULL;
     1873#endif
     1874
     1875        memset(&xce->php->op_array_info, 0, sizeof(xce->php->op_array_info));
    18941876
    18951877        zend_try {
    1896             op_array = xc_compile_php(xce, xce->entry.data.php, h, type TSRMLS_CC);
     1878            op_array = xc_compile_php(xce, xce->php, h, type TSRMLS_CC);
    18971879        } zend_catch {
    18981880            catched = 1;
     
    19041886
    19051887        /* not cachable */
    1906         if (!xce->entry.data.php->op_array) {
     1888        if (!xce->php->op_array) {
    19071889            cache->compiling = 0;
    19081890            /* it's not cachable, but don't scare the users with high misses */
     
    19351917        /* php_store */
    19361918        if (newlycompiled) {
    1937             stored_php = xc_php_store_dmz(xce->entry.data.php TSRMLS_CC);
     1919            stored_php = xc_php_store_dmz(cache, xce->php TSRMLS_CC);
    19381920            if (!stored_php) {
    19391921                /* error */
     
    19431925        /* entry_store */
    19441926        xc_php_addref_dmz(stored_php);
    1945         stored_xce = xc_entry_php_store_dmz(xce TSRMLS_CC);
     1927        stored_xce = xc_entry_php_store_dmz(cache, entry_hash->entryslotid, xce TSRMLS_CC);
    19461928        if (stored_xce) {
    1947             stored_xce->entry.data.php = stored_php;
     1929            stored_xce->php = stored_php;
    19481930        }
    19491931        else {
    19501932            /* error */
    1951             xc_php_release_dmz(stored_php);
     1933            xc_php_release_dmz(cache, stored_php);
    19521934        }
    19531935    } LEAVE_LOCK_EX(cache);
     
    19611943
    19621944    if (newlycompiled) {
    1963         xc_free_php(xce->entry.data.php TSRMLS_CC);
     1945        xc_free_php(xce->php TSRMLS_CC);
    19641946    }
    19651947
     
    19921974err_aftersandbox:
    19931975    if (newlycompiled) {
    1994         xc_free_php(xce->entry.data.php TSRMLS_CC);
     1976        xc_free_php(xce->php TSRMLS_CC);
    19951977        xc_sandbox_free(&sandbox, XC_NoInstall TSRMLS_CC);
    19961978    }
     
    20081990    zend_op_array *op_array;
    20091991    xc_entry_php_t xce;
     1992    xc_entry_hash_t entry_hash;
    20101993    xc_entry_data_php_t php;
    20111994    const char *filename;
     
    20212004    /* {{{ entry_init_key */
    20222005    filename = h->opened_path ? h->opened_path : h->filename;
    2023     xce.entry.data.php = &php;
    2024     if (xc_entry_init_key_php(&xce, filename TSRMLS_CC) != SUCCESS) {
     2006    xce.php = &php;
     2007    if (xc_entry_init_key_php(&entry_hash, &xce, filename TSRMLS_CC) != SUCCESS) {
    20252008        TRACE("failed to init key for %s", filename);
    20262009        return old_compile_file(h, type TSRMLS_CC);
     
    20282011    /* }}} */
    20292012
    2030     op_array = xc_compile_file_ex(&xce, h, type TSRMLS_CC);
     2013    op_array = xc_compile_file_ex(&entry_hash, &xce, h, type TSRMLS_CC);
    20312014
    20322015    xc_entry_free_key_php(&xce TSRMLS_CC);
     
    25962579                }
    25972580                else {
    2598                     xc_filllist_dmz(cache, return_value TSRMLS_CC);
     2581                    xc_filllist_dmz(type, cache, return_value TSRMLS_CC);
    25992582                }
    26002583            } LEAVE_LOCK(cache);
     
    26032586            {
    26042587                xc_entry_t *e, *next;
    2605                 int i, c;
     2588                int entryslotid, c;
    26062589
    26072590                if (id < 0 || id >= size) {
     
    26122595                cache = caches[id];
    26132596                ENTER_LOCK(cache) {
    2614                     for (i = 0, c = cache->hentry->size; i < c; i ++) {
    2615                         for (e = cache->entries[i]; e; e = next) {
     2597                    for (entryslotid = 0, c = cache->hentry->size; entryslotid < c; entryslotid ++) {
     2598                        for (e = cache->entries[entryslotid]; e; e = next) {
    26162599                            next = e->next;
    2617                             xc_entry_remove_dmz(e TSRMLS_CC);
     2600                            xc_entry_remove_dmz(type, cache, entryslotid, e TSRMLS_CC);
    26182601                        }
    2619                         cache->entries[i] = NULL;
     2602                        cache->entries[entryslotid] = NULL;
    26202603                    }
    26212604                } LEAVE_LOCK(cache);
     
    26622645} while (0)
    26632646
    2664 static int xc_entry_init_key_var(xc_entry_t *xce, zval *name TSRMLS_DC) /* {{{ */
     2647static int xc_entry_init_key_var(xc_entry_hash_t *entry_hash, xc_entry_var_t *xce, zval *name TSRMLS_DC) /* {{{ */
    26652648{
    26662649    xc_hash_value_t hv;
    2667     int cacheid;
    26682650
    26692651    switch (Z_TYPE_P(name)) {
     
    26812663    }
    26822664#ifdef IS_UNICODE
    2683     xce->name_type = name->type;
    2684 #endif
    2685     xce->name = name->value;
    2686 
    2687     hv = xc_entry_hash_var(xce TSRMLS_CC);
    2688 
    2689     cacheid = (hv & xc_var_hcache.mask);
    2690     xce->cache = xc_var_caches[cacheid];
     2665    xce->entry.name_type = name->type;
     2666#endif
     2667    xce->entry.name = name->value;
     2668
     2669    hv = xc_entry_hash_var((xc_entry_t *) xce TSRMLS_CC);
     2670
     2671    entry_hash->cacheslotid = (hv & xc_var_hcache.mask);
    26912672    hv >>= xc_var_hcache.bits;
    2692     xce->hvalue = (hv & xc_var_hentry.mask);
    2693 
    2694     xce->type = XC_TYPE_VAR;
     2673    entry_hash->entryslotid = (hv & xc_var_hentry.mask);
    26952674    return SUCCESS;
    26962675}
     
    27002679PHP_FUNCTION(xcache_get)
    27012680{
    2702     xc_entry_t xce, *stored_xce;
     2681    xc_entry_hash_t entry_hash;
     2682    xc_cache_t *cache;
     2683    xc_entry_var_t xce, *stored_xce;
    27032684    zval *name;
    27042685    int found = 0;
     
    27122693        return;
    27132694    }
    2714     xc_entry_init_key_var(&xce, name TSRMLS_CC);
    2715 
    2716     ENTER_LOCK(xce.cache) {
    2717         stored_xce = xc_entry_find_dmz(&xce TSRMLS_CC);
     2695    xc_entry_init_key_var(&entry_hash, &xce, name TSRMLS_CC);
     2696    cache = xc_var_caches[entry_hash.cacheslotid];
     2697
     2698    ENTER_LOCK(cache) {
     2699        stored_xce = (xc_entry_var_t *) xc_entry_find_dmz(XC_TYPE_VAR, cache, entry_hash.cacheslotid, (xc_entry_t *) &xce TSRMLS_CC);
    27182700        if (stored_xce) {
    2719             if (!VAR_ENTRY_EXPIRED(stored_xce)) {
     2701            if (!VAR_ENTRY_EXPIRED(&stored_xce->entry)) {
    27202702                found = 1;
    2721                 xc_processor_restore_zval(return_value, stored_xce->data.var.value, stored_xce->data.var.have_references TSRMLS_CC);
     2703                xc_processor_restore_zval(return_value, stored_xce->value, stored_xce->have_references TSRMLS_CC);
    27222704                /* return */
    27232705                break;
    27242706            }
    27252707            else {
    2726                 xc_entry_remove_dmz(stored_xce TSRMLS_CC);
     2708                xc_entry_remove_dmz(XC_TYPE_VAR, cache, entry_hash.cacheslotid, (xc_entry_t *) stored_xce TSRMLS_CC);
    27272709            }
    27282710        }
    27292711
    27302712        RETVAL_NULL();
    2731     } LEAVE_LOCK(xce.cache);
     2713    } LEAVE_LOCK(cache);
    27322714    if (found) {
    2733         xc_cache_hit_dmz(xce.cache TSRMLS_CC);
     2715        xc_cache_hit_dmz(cache TSRMLS_CC);
    27342716    }
    27352717    else {
    2736         xce.cache->misses ++;
     2718        cache->misses ++;
    27372719    }
    27382720}
     
    27422724PHP_FUNCTION(xcache_set)
    27432725{
    2744     xc_entry_t xce, *stored_xce;
     2726    xc_entry_hash_t entry_hash;
     2727    xc_cache_t *cache;
     2728    xc_entry_var_t xce, *stored_xce;
    27452729    zval *name;
    27462730    zval *value;
     
    27512735    }
    27522736
    2753     xce.ttl = XG(var_ttl);
    2754     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz|l", &name, &value, &xce.ttl) == FAILURE) {
     2737    xce.entry.ttl = XG(var_ttl);
     2738    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz|l", &name, &value, &xce.entry.ttl) == FAILURE) {
    27552739        return;
    27562740    }
    27572741
    27582742    /* max ttl */
    2759     if (xc_var_maxttl && (!xce.ttl || xce.ttl > xc_var_maxttl)) {
    2760         xce.ttl = xc_var_maxttl;
    2761     }
    2762 
    2763     xc_entry_init_key_var(&xce, name TSRMLS_CC);
    2764 
    2765     ENTER_LOCK(xce.cache) {
    2766         stored_xce = xc_entry_find_dmz(&xce TSRMLS_CC);
     2743    if (xc_var_maxttl && (!xce.entry.ttl || xce.entry.ttl > xc_var_maxttl)) {
     2744        xce.entry.ttl = xc_var_maxttl;
     2745    }
     2746
     2747    xc_entry_init_key_var(&entry_hash, &xce, name TSRMLS_CC);
     2748    cache = xc_var_caches[entry_hash.cacheslotid];
     2749
     2750    ENTER_LOCK(cache) {
     2751        stored_xce = (xc_entry_var_t *) xc_entry_find_dmz(XC_TYPE_VAR, cache, entry_hash.entryslotid, (xc_entry_t *) &xce TSRMLS_CC);
    27672752        if (stored_xce) {
    2768             xc_entry_remove_dmz(stored_xce TSRMLS_CC);
    2769         }
    2770         xce.data.var.value = value;
    2771         RETVAL_BOOL(xc_entry_store_dmz(&xce TSRMLS_CC) != NULL ? 1 : 0);
    2772     } LEAVE_LOCK(xce.cache);
     2753            xc_entry_remove_dmz(XC_TYPE_VAR, cache, entry_hash.entryslotid, (xc_entry_t *) stored_xce TSRMLS_CC);
     2754        }
     2755        xce.value = value;
     2756        RETVAL_BOOL(xc_entry_store_dmz(XC_TYPE_VAR, cache, entry_hash.entryslotid, (xc_entry_t *) &xce TSRMLS_CC) != NULL ? 1 : 0);
     2757    } LEAVE_LOCK(cache);
    27732758}
    27742759/* }}} */
     
    27772762PHP_FUNCTION(xcache_isset)
    27782763{
    2779     xc_entry_t xce, *stored_xce;
     2764    xc_entry_hash_t entry_hash;
     2765    xc_cache_t *cache;
     2766    xc_entry_var_t xce, *stored_xce;
    27802767    zval *name;
    27812768    int found = 0;
     
    27892776        return;
    27902777    }
    2791     xc_entry_init_key_var(&xce, name TSRMLS_CC);
    2792 
    2793     ENTER_LOCK(xce.cache) {
    2794         stored_xce = xc_entry_find_dmz(&xce TSRMLS_CC);
     2778    xc_entry_init_key_var(&entry_hash, &xce, name TSRMLS_CC);
     2779    cache = xc_var_caches[entry_hash.cacheslotid];
     2780
     2781    ENTER_LOCK(cache) {
     2782        stored_xce = (xc_entry_var_t *) xc_entry_find_dmz(XC_TYPE_VAR, cache, entry_hash.entryslotid, (xc_entry_t *) &xce TSRMLS_CC);
    27952783        if (stored_xce) {
    2796             if (!VAR_ENTRY_EXPIRED(stored_xce)) {
     2784            if (!VAR_ENTRY_EXPIRED(&stored_xce->entry)) {
    27972785                found = 1;
    27982786                RETVAL_TRUE;
     
    28012789            }
    28022790            else {
    2803                 xc_entry_remove_dmz(stored_xce TSRMLS_CC);
     2791                xc_entry_remove_dmz(XC_TYPE_VAR, cache, entry_hash.entryslotid, (xc_entry_t *) stored_xce TSRMLS_CC);
    28042792            }
    28052793        }
    28062794
    28072795        RETVAL_FALSE;
    2808     } LEAVE_LOCK(xce.cache);
     2796    } LEAVE_LOCK(cache);
    28092797    if (found) {
    2810         xc_cache_hit_dmz(xce.cache TSRMLS_CC);
     2798        xc_cache_hit_dmz(cache TSRMLS_CC);
    28112799    }
    28122800    else {
    2813         xce.cache->misses ++;
     2801        cache->misses ++;
    28142802    }
    28152803}
     
    28192807PHP_FUNCTION(xcache_unset)
    28202808{
    2821     xc_entry_t xce, *stored_xce;
     2809    xc_entry_hash_t entry_hash;
     2810    xc_cache_t *cache;
     2811    xc_entry_var_t xce, *stored_xce;
    28222812    zval *name;
    28232813
     
    28302820        return;
    28312821    }
    2832     xc_entry_init_key_var(&xce, name TSRMLS_CC);
    2833 
    2834     ENTER_LOCK(xce.cache) {
    2835         stored_xce = xc_entry_find_dmz(&xce TSRMLS_CC);
     2822    xc_entry_init_key_var(&entry_hash, &xce, name TSRMLS_CC);
     2823    cache = xc_var_caches[entry_hash.cacheslotid];
     2824
     2825    ENTER_LOCK(cache) {
     2826        stored_xce = (xc_entry_var_t *) xc_entry_find_dmz(XC_TYPE_VAR, cache, entry_hash.entryslotid, (xc_entry_t *) &xce TSRMLS_CC);
    28362827        if (stored_xce) {
    2837             xc_entry_remove_dmz(stored_xce TSRMLS_CC);
     2828            xc_entry_remove_dmz(XC_TYPE_VAR, cache, entry_hash.entryslotid, (xc_entry_t *) stored_xce TSRMLS_CC);
    28382829            RETVAL_TRUE;
    28392830        }
     
    28412832            RETVAL_FALSE;
    28422833        }
    2843     } LEAVE_LOCK(xce.cache);
     2834    } LEAVE_LOCK(cache);
    28442835}
    28452836/* }}} */
     
    28632854        xc_cache_t *cache = xc_var_caches[i];
    28642855        ENTER_LOCK(cache) {
    2865             int j, jend;
    2866             for (j = 0, jend = cache->hentry->size; j < jend; j ++) {
     2856            int entryslotid, jend;
     2857            for (entryslotid = 0, jend = cache->hentry->size; entryslotid < jend; entryslotid ++) {
    28672858                xc_entry_t *entry, *next;
    2868                 for (entry = cache->entries[j]; entry; entry = next) {
     2859                for (entry = cache->entries[entryslotid]; entry; entry = next) {
    28692860                    next = entry->next;
    2870                     if (xc_entry_has_prefix_dmz(entry, prefix)) {
    2871                         xc_entry_remove_dmz(entry TSRMLS_CC);
     2861                    if (xc_entry_has_prefix_dmz(XC_TYPE_VAR, entry, prefix)) {
     2862                        xc_entry_remove_dmz(XC_TYPE_VAR, cache, entryslotid, entry TSRMLS_CC);
    28722863                    }
    28732864                }
     
    28792870static inline void xc_var_inc_dec(int inc, INTERNAL_FUNCTION_PARAMETERS) /* {{{ */
    28802871{
    2881     xc_entry_t xce, *stored_xce;
     2872    xc_entry_hash_t entry_hash;
     2873    xc_cache_t *cache;
     2874    xc_entry_var_t xce, *stored_xce;
    28822875    zval *name;
    28832876    long count = 1;
     
    28902883    }
    28912884
    2892     xce.ttl = XG(var_ttl);
    2893     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|ll", &name, &count, &xce.ttl) == FAILURE) {
     2885    xce.entry.ttl = XG(var_ttl);
     2886    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|ll", &name, &count, &xce.entry.ttl) == FAILURE) {
    28942887        return;
    28952888    }
    28962889
    28972890    /* max ttl */
    2898     if (xc_var_maxttl && (!xce.ttl || xce.ttl > xc_var_maxttl)) {
    2899         xce.ttl = xc_var_maxttl;
    2900     }
    2901 
    2902     xc_entry_init_key_var(&xce, name TSRMLS_CC);
    2903 
    2904     ENTER_LOCK(xce.cache) {
    2905         stored_xce = xc_entry_find_dmz(&xce TSRMLS_CC);
     2891    if (xc_var_maxttl && (!xce.entry.ttl || xce.entry.ttl > xc_var_maxttl)) {
     2892        xce.entry.ttl = xc_var_maxttl;
     2893    }
     2894
     2895    xc_entry_init_key_var(&entry_hash, &xce, name TSRMLS_CC);
     2896    cache = xc_var_caches[entry_hash.cacheslotid];
     2897
     2898    ENTER_LOCK(cache) {
     2899        stored_xce = (xc_entry_var_t *) xc_entry_find_dmz(XC_TYPE_VAR, cache, entry_hash.cacheslotid, (xc_entry_t *) &xce TSRMLS_CC);
    29062900        if (stored_xce) {
    29072901            TRACE("incdec: gotxce %s", xce.name.str.val);
    29082902            /* timeout */
    2909             if (VAR_ENTRY_EXPIRED(stored_xce)) {
     2903            if (VAR_ENTRY_EXPIRED(&(stored_xce->entry))) {
    29102904                TRACE("%s", "incdec: expired");
    2911                 xc_entry_remove_dmz(stored_xce TSRMLS_CC);
     2905                xc_entry_remove_dmz(XC_TYPE_VAR, cache, entry_hash.cacheslotid, (xc_entry_t *) stored_xce TSRMLS_CC);
    29122906                stored_xce = NULL;
    29132907            }
    29142908            else {
    29152909                /* do it in place */
    2916                 xc_entry_data_var_t *stored_var = &stored_xce->data.var;
    2917                 if (Z_TYPE_P(stored_var->value) == IS_LONG) {
     2910                if (Z_TYPE_P(stored_xce->value) == IS_LONG) {
    29182911                    zval *zv;
    2919                     stored_xce->ctime = XG(request_time);
    2920                     stored_xce->ttl   = xce.ttl;
     2912                    stored_xce->entry.ctime = XG(request_time);
     2913                    stored_xce->entry.ttl   = xce.entry.ttl;
    29212914                    TRACE("%s", "incdec: islong");
    2922                     value = Z_LVAL_P(stored_var->value);
     2915                    value = Z_LVAL_P(stored_xce->value);
    29232916                    value += (inc == 1 ? count : - count);
    29242917                    RETVAL_LONG(value);
    29252918
    2926                     zv = (zval *) xce.cache->shm->handlers->to_readwrite(xce.cache->shm, (char *) stored_var->value);
     2919                    zv = (zval *) cache->shm->handlers->to_readwrite(cache->shm, (char *) stored_xce->value);
    29272920                    Z_LVAL_P(zv) = value;
    29282921                    break; /* leave lock */
     
    29302923                else {
    29312924                    TRACE("%s", "incdec: notlong");
    2932                     xc_processor_restore_zval(&oldzval, stored_xce->data.var.value, stored_xce->data.var.have_references TSRMLS_CC);
     2925                    xc_processor_restore_zval(&oldzval, stored_xce->value, stored_xce->have_references TSRMLS_CC);
    29332926                    convert_to_long(&oldzval);
    29342927                    value = Z_LVAL(oldzval);
     
    29432936        value += (inc == 1 ? count : - count);
    29442937        RETVAL_LONG(value);
    2945         stored_xce->data.var.value = return_value;
     2938        stored_xce->value = return_value;
    29462939
    29472940        if (stored_xce) {
    2948             xce.atime = stored_xce->atime;
    2949             xce.ctime = stored_xce->ctime;
    2950             xce.hits  = stored_xce->hits;
    2951             xc_entry_remove_dmz(stored_xce TSRMLS_CC);
    2952         }
    2953         xc_entry_store_dmz(&xce TSRMLS_CC);
    2954 
    2955     } LEAVE_LOCK(xce.cache);
     2941            xce.entry.atime = stored_xce->entry.atime;
     2942            xce.entry.ctime = stored_xce->entry.ctime;
     2943            xce.entry.hits  = stored_xce->entry.hits;
     2944            xc_entry_remove_dmz(XC_TYPE_VAR, cache, entry_hash.cacheslotid, (xc_entry_t *) stored_xce TSRMLS_CC);
     2945        }
     2946        xc_entry_store_dmz(XC_TYPE_VAR, cache, entry_hash.cacheslotid, (xc_entry_t *) &xce TSRMLS_CC);
     2947
     2948    } LEAVE_LOCK(cache);
    29562949}
    29572950/* }}} */
  • trunk/xcache.h

    r851 r854  
    355355/* }}} */
    356356#endif
    357 typedef enum { XC_TYPE_PHP, XC_TYPE_VAR } xc_entry_type_t;
    358357typedef struct {
    359358    char digest[16];
     
    369368/* {{{ xc_entry_data_php_t */
    370369struct _xc_entry_data_php_t {
     370    xc_entry_data_php_t *next;
    371371    xc_hash_value_t      hvalue;
    372     xc_entry_data_php_t *next;
    373     xc_cache_t          *cache;
    374372
    375373    xc_md5sum_t md5;        /* md5sum of the source */
     
    410408};
    411409/* }}} */
    412 /* {{{ xc_entry_data_var_t */
    413 typedef struct {
    414     zval   *value;
    415 
    416     zend_bool  have_references;
    417 } xc_entry_data_var_t;
    418 /* }}} */
    419410typedef zvalue_value xc_entry_name_t;
    420411/* {{{ xc_entry_t */
    421412struct _xc_entry_t {
    422     xc_hash_value_t hvalue;
    423     xc_entry_t     *next;
    424     xc_cache_t     *cache;
    425 
    426     xc_entry_type_t type;
    427     size_t          size;
    428 
     413    xc_entry_t *next;
     414
     415    size_t     size;
    429416    time_t     ctime;           /* creation ctime of this entry */
    430417    time_t     atime;           /*   access atime of this entry */
     
    437424#endif
    438425    xc_entry_name_t name;
    439 
    440     union {
    441         xc_entry_data_php_t *php;
    442         xc_entry_data_var_t var;
    443     } data;
    444426};
    445427
    446428typedef struct {
    447429    xc_entry_t entry;
     430    xc_entry_data_php_t *php;
    448431
    449432    zend_ulong refcount;    /* count of php instances holding this entry */
     
    466449} xc_entry_php_t;
    467450/* }}} */
     451typedef struct {
     452    xc_entry_t entry;
     453    zval      *value;
     454    zend_bool  have_references;
     455} xc_entry_var_t;
     456/* }}} */
     457typedef struct xc_entry_hash_t { /* {{{ */
     458    xc_hash_value_t cacheslotid;
     459    xc_hash_value_t entryslotid;
     460} xc_entry_hash_t;
     461/* }}} */
    468462
    469463extern zend_module_entry xcache_module_entry;
Note: See TracChangeset for help on using the changeset viewer.