Changeset 1062 for trunk


Ignore:
Timestamp:
2012-07-27T17:10:17+02:00 (2 years ago)
Author:
moo
Message:

const some mem handlers
split non-shared data from shm
make editor goto file correctly

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:ignore
      •  

        old new  
        1818devel.ini 
        1919devel.php 
         20devel.fpm 
        2021.gdb_history 
        2122include 
  • trunk/devel/run

    r1053 r1062  
    147147 
    148148LANG=C /usr/bin/make $MAKEOPTS "${MAKEARGS[@]}" 2>&1 \ 
    149 | sed -ur 's#Werror=implicit-function-declaration#We/rror=i/mplicit-function-declaration#' \ 
     149| sed -ur \ 
     150    -e 's#Werror=implicit-function-declaration#We/rror=i/mplicit-function-declaration#' \ 
     151    -e 's#\./xc_processor\.h#'$PWD'/xc_processor.h#' \ 
     152    -e 's#\./xc_processor\.c\.h#'$PWD'/xc_processor.c.h#' \ 
    150153| hi error implicit warn FAIL 
    151154ret=${PIPESTATUS[0]} 
  • trunk/mod_cacher/xc_cache.h

    r1051 r1062  
    1111typedef ulong xc_hash_value_t; 
    1212typedef struct _xc_hash_t xc_hash_t; 
     13typedef struct _xc_cached_t xc_cached_t; 
    1314typedef struct _xc_entry_t xc_entry_t; 
    1415typedef struct _xc_entry_data_php_t xc_entry_data_php_t; 
     
    1617struct _xc_lock_t; 
    1718struct _xc_shm_t; 
    18 /* {{{ xc_cache_t */ 
     19/* {{{ xc_cache_t: only cache info, not in shm */ 
    1920typedef struct { 
    2021    int cacheid; 
    2122    xc_hash_t  *hcache; /* hash to cacheid */ 
    2223 
    23     time_t     compiling; 
    24     zend_ulong updates; 
    25     zend_ulong hits; 
    26     zend_ulong clogs; 
    27     zend_ulong ooms; 
    28     zend_ulong errors; 
    2924    struct _xc_lock_t  *lck; 
    3025    struct _xc_shm_t   *shm; /* which shm contains us */ 
    3126    struct _xc_mem_t   *mem; /* which mem contains us */ 
    3227 
    33     xc_entry_t **entries; 
    34     int entries_count; 
    35     xc_entry_data_php_t **phps; 
    36     int phps_count; 
    37     xc_entry_t *deletes; 
    38     int deletes_count; 
    3928    xc_hash_t  *hentry; /* hash settings to entry */ 
    4029    xc_hash_t  *hphp;   /* hash settings to php */ 
    41  
    42     time_t     last_gc_deletes; 
    43     time_t     last_gc_expires; 
    44  
    45     time_t     hits_by_hour_cur_time; 
    46     zend_uint  hits_by_hour_cur_slot; 
    47     zend_ulong hits_by_hour[24]; 
    48     time_t     hits_by_second_cur_time; 
    49     zend_uint  hits_by_second_cur_slot; 
    50     zend_ulong hits_by_second[5]; 
     30    xc_cached_t *cached; 
    5131} xc_cache_t; 
    5232/* }}} */ 
  • trunk/mod_cacher/xc_cacher.c

    r1057 r1062  
    5959/* }}} */ 
    6060 
    61 /* {{{ types */ 
    62 struct _xc_hash_t { 
     61struct _xc_hash_t { /* {{{ */ 
    6362    size_t bits; 
    6463    size_t size; 
    6564    xc_hash_value_t mask; 
     65}; 
     66/* }}} */ 
     67struct _xc_cached_t { /* {{{ stored in shm */ 
     68    int cacheid; 
     69 
     70    time_t     compiling; 
     71    zend_ulong updates; 
     72    zend_ulong hits; 
     73    zend_ulong clogs; 
     74    zend_ulong ooms; 
     75    zend_ulong errors; 
     76 
     77    xc_entry_t **entries; 
     78    int entries_count; 
     79    xc_entry_data_php_t **phps; 
     80    int phps_count; 
     81    xc_entry_t *deletes; 
     82    int deletes_count; 
     83 
     84    time_t     last_gc_deletes; 
     85    time_t     last_gc_expires; 
     86 
     87    time_t     hits_by_hour_cur_time; 
     88    zend_uint  hits_by_hour_cur_slot; 
     89    zend_ulong hits_by_hour[24]; 
     90    time_t     hits_by_second_cur_time; 
     91    zend_uint  hits_by_second_cur_slot; 
     92    zend_ulong hits_by_second[5]; 
    6693}; 
    6794/* }}} */ 
     
    88115static zend_ulong xc_var_size  = 0; 
    89116 
    90 static xc_cache_t **xc_php_caches = NULL; 
    91 static xc_cache_t **xc_var_caches = NULL; 
     117static xc_cache_t *xc_php_caches = NULL; 
     118static xc_cache_t *xc_var_caches = NULL; 
    92119 
    93120static zend_bool xc_initized = 0; 
     
    114141/* any function in *_unlocked is only safe be called within locked (single thread access) area */ 
    115142 
    116 static void xc_php_add_unlocked(xc_cache_t *cache, xc_entry_data_php_t *php) /* {{{ */ 
    117 { 
    118     xc_entry_data_php_t **head = &(cache->phps[php->hvalue]); 
     143static void xc_php_add_unlocked(xc_cached_t *cached, xc_entry_data_php_t *php) /* {{{ */ 
     144{ 
     145    xc_entry_data_php_t **head = &(cached->phps[php->hvalue]); 
    119146    php->next = *head; 
    120147    *head = php; 
    121     cache->phps_count ++; 
     148    cached->phps_count ++; 
    122149} 
    123150/* }}} */ 
     
    130157    stored_php = xc_processor_store_xc_entry_data_php_t(cache, php TSRMLS_CC); 
    131158    if (stored_php) { 
    132         xc_php_add_unlocked(cache, stored_php); 
     159        xc_php_add_unlocked(cache->cached, stored_php); 
    133160        return stored_php; 
    134161    } 
    135162    else { 
    136         cache->ooms ++; 
     163        cache->cached->ooms ++; 
    137164        return NULL; 
    138165    } 
    139166} 
    140167/* }}} */ 
    141 static xc_entry_data_php_t *xc_php_find_unlocked(xc_cache_t *cache, xc_entry_data_php_t *php TSRMLS_DC) /* {{{ */ 
     168static xc_entry_data_php_t *xc_php_find_unlocked(xc_cached_t *cached, xc_entry_data_php_t *php TSRMLS_DC) /* {{{ */ 
    142169{ 
    143170    xc_entry_data_php_t *p; 
    144     for (p = cache->phps[php->hvalue]; p; p = (xc_entry_data_php_t *) p->next) { 
     171    for (p = cached->phps[php->hvalue]; p; p = (xc_entry_data_php_t *) p->next) { 
    145172        if (memcmp(&php->md5.digest, &p->md5.digest, sizeof(php->md5.digest)) == 0) { 
    146173            p->hits ++; 
     
    164191{ 
    165192    if (-- php->refcount == 0) { 
    166         xc_entry_data_php_t **pp = &(cache->phps[php->hvalue]); 
     193        xc_entry_data_php_t **pp = &(cache->cached->phps[php->hvalue]); 
    167194        xc_entry_data_php_t *p; 
    168195        for (p = *pp; p; pp = &(p->next), p = p->next) { 
     
    259286} 
    260287/* }}} */ 
    261 static void xc_entry_add_unlocked(xc_cache_t *cache, xc_hash_value_t entryslotid, xc_entry_t *entry) /* {{{ */ 
    262 { 
    263     xc_entry_t **head = &(cache->entries[entryslotid]); 
     288static void xc_entry_add_unlocked(xc_cached_t *cached, xc_hash_value_t entryslotid, xc_entry_t *entry) /* {{{ */ 
     289{ 
     290    xc_entry_t **head = &(cached->entries[entryslotid]); 
    264291    entry->next = *head; 
    265292    *head = entry; 
    266     cache->entries_count ++; 
     293    cached->entries_count ++; 
    267294} 
    268295/* }}} */ 
     
    278305        : (xc_entry_t *) xc_processor_store_xc_entry_var_t(cache, (xc_entry_var_t *) entry TSRMLS_CC); 
    279306    if (stored_entry) { 
    280         xc_entry_add_unlocked(cache, entryslotid, stored_entry); 
    281         ++cache->updates; 
     307        xc_entry_add_unlocked(cache->cached, entryslotid, stored_entry); 
     308        ++cache->cached->updates; 
    282309        return stored_entry; 
    283310    } 
    284311    else { 
    285         cache->ooms ++; 
     312        cache->cached->ooms ++; 
    286313        return NULL; 
    287314    } 
     
    308335static void xc_entry_free_unlocked(xc_entry_type_t type, xc_cache_t *cache, xc_entry_t *entry TSRMLS_DC) /* {{{ */ 
    309336{ 
    310     cache->entries_count --; 
     337    cache->cached->entries_count --; 
    311338    if ((type == XC_TYPE_PHP ? ((xc_entry_php_t *) entry)->refcount : 0) == 0) { 
    312339        xc_entry_free_real_unlocked(type, cache, entry); 
    313340    } 
    314341    else { 
    315         entry->next = cache->deletes; 
    316         cache->deletes = entry; 
     342        entry->next = cache->cached->deletes; 
     343        cache->cached->deletes = entry; 
    317344        entry->dtime = XG(request_time); 
    318         cache->deletes_count ++; 
     345        cache->cached->deletes_count ++; 
    319346    } 
    320347    return; 
     
    323350static void xc_entry_remove_unlocked(xc_entry_type_t type, xc_cache_t *cache, xc_hash_value_t entryslotid, xc_entry_t *entry TSRMLS_DC) /* {{{ */ 
    324351{ 
    325     xc_entry_t **pp = &(cache->entries[entryslotid]); 
     352    xc_entry_t **pp = &(cache->cached->entries[entryslotid]); 
    326353    xc_entry_t *p; 
    327354    for (p = *pp; p; pp = &(p->next), p = p->next) { 
     
    339366{ 
    340367    xc_entry_t *p; 
    341     for (p = cache->entries[entryslotid]; p; p = p->next) { 
     368    for (p = cache->cached->entries[entryslotid]; p; p = p->next) { 
    342369        if (xc_entry_equal_unlocked(type, entry, p TSRMLS_CC)) { 
    343370            zend_bool fresh; 
     
    407434} 
    408435/* }}} */ 
    409 static inline void xc_cache_hit_unlocked(xc_cache_t *cache TSRMLS_DC) /* {{{ */ 
    410 { 
    411     cache->hits ++; 
    412  
    413     xc_counters_inc(&cache->hits_by_hour_cur_time 
    414             , &cache->hits_by_hour_cur_slot, 60 * 60 
    415             , cache->hits_by_hour 
    416             , sizeof(cache->hits_by_hour) / sizeof(cache->hits_by_hour[0]) 
     436static inline void xc_cached_hit_unlocked(xc_cached_t *cached TSRMLS_DC) /* {{{ */ 
     437{ 
     438    cached->hits ++; 
     439 
     440    xc_counters_inc(&cached->hits_by_hour_cur_time 
     441            , &cached->hits_by_hour_cur_slot, 60 * 60 
     442            , cached->hits_by_hour 
     443            , sizeof(cached->hits_by_hour) / sizeof(cached->hits_by_hour[0]) 
    417444            TSRMLS_CC); 
    418445 
    419     xc_counters_inc(&cache->hits_by_second_cur_time 
    420             , &cache->hits_by_second_cur_slot, 1 
    421             , cache->hits_by_second 
    422             , sizeof(cache->hits_by_second) / sizeof(cache->hits_by_second[0]) 
     446    xc_counters_inc(&cached->hits_by_second_cur_time 
     447            , &cached->hits_by_second_cur_slot, 1 
     448            , cached->hits_by_second 
     449            , sizeof(cached->hits_by_second) / sizeof(cached->hits_by_second[0]) 
    423450            TSRMLS_CC); 
    424451} 
     
    434461 
    435462    for (i = 0, c = cache->hentry->size; i < c; i ++) { 
    436         pp = &(cache->entries[i]); 
     463        pp = &(cache->cached->entries[i]); 
    437464        for (p = *pp; p; p = *pp) { 
    438465            if (apply_func(p TSRMLS_CC)) { 
     
    473500static void xc_gc_expires_one(xc_entry_type_t type, xc_cache_t *cache, zend_ulong gc_interval, cache_apply_unlocked_func_t apply_func TSRMLS_DC) /* {{{ */ 
    474501{ 
    475     TRACE("interval %lu, %lu %lu", (zend_ulong) XG(request_time), (zend_ulong) cache->last_gc_expires, gc_interval); 
    476     if (XG(request_time) >= cache->last_gc_expires + (time_t) gc_interval) { 
     502    TRACE("interval %lu, %lu %lu", (zend_ulong) XG(request_time), (zend_ulong) cache->cached->last_gc_expires, gc_interval); 
     503    if (XG(request_time) >= cache->cached->last_gc_expires + (time_t) gc_interval) { 
    477504        ENTER_LOCK(cache) { 
    478             if (XG(request_time) >= cache->last_gc_expires + (time_t) gc_interval) { 
    479                 cache->last_gc_expires = XG(request_time); 
     505            if (XG(request_time) >= cache->cached->last_gc_expires + (time_t) gc_interval) { 
     506                cache->cached->last_gc_expires = XG(request_time); 
    480507                xc_entry_apply_unlocked(type, cache, apply_func TSRMLS_CC); 
    481508            } 
     
    493520 
    494521    for (i = 0, c = xc_php_hcache.size; i < c; i ++) { 
    495         xc_gc_expires_one(XC_TYPE_PHP, xc_php_caches[i], xc_php_gc_interval, xc_gc_expires_php_entry_unlocked TSRMLS_CC); 
     522        xc_gc_expires_one(XC_TYPE_PHP, &xc_php_caches[i], xc_php_gc_interval, xc_gc_expires_php_entry_unlocked TSRMLS_CC); 
    496523    } 
    497524} 
     
    506533 
    507534    for (i = 0, c = xc_var_hcache.size; i < c; i ++) { 
    508         xc_gc_expires_one(XC_TYPE_VAR, xc_var_caches[i], xc_var_gc_interval, xc_gc_expires_var_entry_unlocked TSRMLS_CC); 
     535        xc_gc_expires_one(XC_TYPE_VAR, &xc_var_caches[i], xc_var_gc_interval, xc_gc_expires_var_entry_unlocked TSRMLS_CC); 
    509536    } 
    510537} 
     
    515542    xc_entry_t *p, **pp; 
    516543 
    517     pp = &cache->deletes; 
     544    pp = &cache->cached->deletes; 
    518545    for (p = *pp; p; p = *pp) { 
    519546        xc_entry_php_t *entry = (xc_entry_php_t *) p; 
     
    525552            /* unlink */ 
    526553            *pp = p->next; 
    527             cache->deletes_count --; 
     554            cache->cached->deletes_count --; 
    528555            xc_entry_free_real_unlocked(XC_TYPE_PHP, cache, p); 
    529556        } 
     
    536563static XC_CACHE_APPLY_FUNC(xc_gc_deletes_one) /* {{{ */ 
    537564{ 
    538     if (cache->deletes && XG(request_time) - cache->last_gc_deletes > xc_deletes_gc_interval) { 
     565    if (cache->cached->deletes && XG(request_time) - cache->cached->last_gc_deletes > xc_deletes_gc_interval) { 
    539566        ENTER_LOCK(cache) { 
    540             if (cache->deletes && XG(request_time) - cache->last_gc_deletes > xc_deletes_gc_interval) { 
    541                 cache->last_gc_deletes = XG(request_time); 
     567            if (cache->cached->deletes && XG(request_time) - cache->cached->last_gc_deletes > xc_deletes_gc_interval) { 
     568                cache->cached->last_gc_deletes = XG(request_time); 
    542569                xc_gc_delete_unlocked(cache TSRMLS_CC); 
    543570            } 
     
    552579    if (xc_php_caches) { 
    553580        for (i = 0, c = xc_php_hcache.size; i < c; i ++) { 
    554             xc_gc_deletes_one(xc_php_caches[i] TSRMLS_CC); 
     581            xc_gc_deletes_one(&xc_php_caches[i] TSRMLS_CC); 
    555582        } 
    556583    } 
     
    558585    if (xc_var_caches) { 
    559586        for (i = 0, c = xc_var_hcache.size; i < c; i ++) { 
    560             xc_gc_deletes_one(xc_var_caches[i] TSRMLS_CC); 
     587            xc_gc_deletes_one(&xc_var_caches[i] TSRMLS_CC); 
    561588        } 
    562589    } 
     
    573600    xc_memsize_t avail = 0; 
    574601#endif 
    575     xc_mem_t *mem = cache->mem; 
     602    const xc_mem_t *mem = cache->mem; 
    576603    const xc_mem_handlers_t *handlers = mem->handlers; 
    577604    zend_ulong interval; 
     605    const xc_cached_t *cached = cache->cached; 
     606 
    578607    if (cachetype == XC_TYPE_PHP) { 
    579608        interval = xc_php_ttl ? xc_php_gc_interval : 0; 
     
    584613 
    585614    add_assoc_long_ex(return_value, ZEND_STRS("slots"),     cache->hentry->size); 
    586     add_assoc_long_ex(return_value, ZEND_STRS("compiling"), cache->compiling); 
    587     add_assoc_long_ex(return_value, ZEND_STRS("updates"),   cache->updates); 
    588     add_assoc_long_ex(return_value, ZEND_STRS("misses"),    cache->updates); /* deprecated */ 
    589     add_assoc_long_ex(return_value, ZEND_STRS("hits"),      cache->hits); 
    590     add_assoc_long_ex(return_value, ZEND_STRS("clogs"),     cache->clogs); 
    591     add_assoc_long_ex(return_value, ZEND_STRS("ooms"),      cache->ooms); 
    592     add_assoc_long_ex(return_value, ZEND_STRS("errors"),    cache->errors); 
    593  
    594     add_assoc_long_ex(return_value, ZEND_STRS("cached"),    cache->entries_count); 
    595     add_assoc_long_ex(return_value, ZEND_STRS("deleted"),   cache->deletes_count); 
     615    add_assoc_long_ex(return_value, ZEND_STRS("compiling"), cached->compiling); 
     616    add_assoc_long_ex(return_value, ZEND_STRS("updates"),   cached->updates); 
     617    add_assoc_long_ex(return_value, ZEND_STRS("misses"),    cached->updates); /* deprecated */ 
     618    add_assoc_long_ex(return_value, ZEND_STRS("hits"),      cached->hits); 
     619    add_assoc_long_ex(return_value, ZEND_STRS("clogs"),     cached->clogs); 
     620    add_assoc_long_ex(return_value, ZEND_STRS("ooms"),      cached->ooms); 
     621    add_assoc_long_ex(return_value, ZEND_STRS("errors"),    cached->errors); 
     622 
     623    add_assoc_long_ex(return_value, ZEND_STRS("cached"),    cached->entries_count); 
     624    add_assoc_long_ex(return_value, ZEND_STRS("deleted"),   cached->deletes_count); 
    596625    if (interval) { 
    597         time_t gc = (cache->last_gc_expires + interval) - XG(request_time); 
     626        time_t gc = (cached->last_gc_expires + interval) - XG(request_time); 
    598627        add_assoc_long_ex(return_value, ZEND_STRS("gc"),    gc > 0 ? gc : 0); 
    599628    } 
     
    603632    MAKE_STD_ZVAL(hits); 
    604633    array_init(hits); 
    605     for (i = 0; i < sizeof(cache->hits_by_hour) / sizeof(cache->hits_by_hour[0]); i ++) { 
    606         add_next_index_long(hits, (long) cache->hits_by_hour[i]); 
     634    for (i = 0; i < sizeof(cached->hits_by_hour) / sizeof(cached->hits_by_hour[0]); i ++) { 
     635        add_next_index_long(hits, (long) cached->hits_by_hour[i]); 
    607636    } 
    608637    add_assoc_zval_ex(return_value, ZEND_STRS("hits_by_hour"), hits); 
     
    610639    MAKE_STD_ZVAL(hits); 
    611640    array_init(hits); 
    612     for (i = 0; i < sizeof(cache->hits_by_second) / sizeof(cache->hits_by_second[0]); i ++) { 
    613         add_next_index_long(hits, (long) cache->hits_by_second[i]); 
     641    for (i = 0; i < sizeof(cached->hits_by_second) / sizeof(cached->hits_by_second[0]); i ++) { 
     642        add_next_index_long(hits, (long) cached->hits_by_second[i]); 
    614643    } 
    615644    add_assoc_zval_ex(return_value, ZEND_STRS("hits_by_second"), hits); 
     
    721750 
    722751    for (i = 0, c = cache->hentry->size; i < c; i ++) { 
    723         for (e = cache->entries[i]; e; e = e->next) { 
     752        for (e = cache->cached->entries[i]; e; e = e->next) { 
    724753            xc_fillentry_unlocked(type, e, i, 0, list TSRMLS_CC); 
    725754        } 
     
    729758    ALLOC_INIT_ZVAL(list); 
    730759    array_init(list); 
    731     for (e = cache->deletes; e; e = e->next) { 
     760    for (e = cache->cached->deletes; e; e = e->next) { 
    732761        xc_fillentry_unlocked(XC_TYPE_PHP, e, 0, 1, list TSRMLS_CC); 
    733762    } 
     
    817846/* }}} */ 
    818847 
    819 static inline void xc_entry_unholds_real(xc_stack_t *holds, xc_cache_t **caches, int cachecount TSRMLS_DC) /* {{{ */ 
     848static inline void xc_entry_unholds_real(xc_stack_t *holds, xc_cache_t *caches, int cachecount TSRMLS_DC) /* {{{ */ 
    820849{ 
    821850    int i; 
     
    828857        TRACE("holded %d items", xc_stack_count(s)); 
    829858        if (xc_stack_count(s)) { 
    830             cache = caches[i]; 
     859            cache = &caches[i]; 
    831860            ENTER_LOCK(cache) { 
    832861                while (xc_stack_count(s)) { 
     
    10241053    *entry_resolve_path_data->stored_entry = (xc_entry_php_t *) xc_entry_find_unlocked( 
    10251054            XC_TYPE_PHP 
    1026             , xc_php_caches[compiler->entry_hash.cacheid] 
     1055            , &xc_php_caches[compiler->entry_hash.cacheid] 
    10271056            , compiler->entry_hash.entryslotid 
    10281057            , (xc_entry_t *) &compiler->new_entry 
     
    18891918    xc_compiler_t *compiler = sandboxed_compiler->compiler; 
    18901919    zend_bool catched = 0; 
    1891     xc_cache_t *cache = xc_php_caches[compiler->entry_hash.cacheid]; 
     1920    xc_cache_t *cache = &xc_php_caches[compiler->entry_hash.cacheid]; 
    18921921    xc_entry_php_t *stored_entry; 
    18931922    xc_entry_data_php_t *stored_php; 
     
    19501979    } 
    19511980 
    1952     cache->compiling = 0; 
     1981    cache->cached->compiling = 0; 
    19531982    xc_free_php(&compiler->new_php TSRMLS_CC); 
    19541983 
     
    19752004    xc_free_php(&compiler->new_php TSRMLS_CC); 
    19762005 
    1977     cache->compiling = 0; 
     2006    cache->cached->compiling = 0; 
    19782007    if (catched) { 
    1979         cache->errors ++; 
     2008        cache->cached->errors ++; 
    19802009        zend_bailout(); 
    19812010    } 
     
    20162045    zend_bool catched = 0; 
    20172046    zend_op_array *op_array; 
    2018     xc_cache_t *cache = xc_php_caches[compiler->entry_hash.cacheid]; 
     2047    xc_cache_t *cache = &xc_php_caches[compiler->entry_hash.cacheid]; 
    20192048    xc_sandboxed_compiler_t sandboxed_compiler; 
    20202049 
    20212050    /* stale clogs precheck */ 
    2022     if (XG(request_time) - cache->compiling < 30) { 
    2023         cache->clogs ++; 
     2051    if (XG(request_time) - cache->cached->compiling < 30) { 
     2052        cache->cached->clogs ++; 
    20242053        return old_compile_file(h, type TSRMLS_CC); 
    20252054    } 
     
    20472076 
    20482077        if (stored_entry) { 
    2049             xc_cache_hit_unlocked(cache TSRMLS_CC); 
     2078            xc_cached_hit_unlocked(cache->cached TSRMLS_CC); 
    20502079 
    20512080            TRACE(" hit %d:%s, holding", compiler->new_entry.file_inode, stored_entry->entry.name.str.val); 
     
    20622091        } 
    20632092 
    2064         stored_php = xc_php_find_unlocked(cache, &compiler->new_php TSRMLS_CC); 
     2093        stored_php = xc_php_find_unlocked(cache->cached, &compiler->new_php TSRMLS_CC); 
    20652094 
    20662095        if (stored_php) { 
     
    20792108        } 
    20802109 
    2081         if (XG(request_time) - cache->compiling < 30) { 
     2110        if (XG(request_time) - cache->cached->compiling < 30) { 
    20822111            TRACE("%s", "miss php, but compiling"); 
    2083             cache->clogs ++; 
     2112            cache->cached->clogs ++; 
    20842113            gaveup = 1; 
    20852114            break; 
     
    20872116 
    20882117        TRACE("%s", "miss php, going to compile"); 
    2089         cache->compiling = XG(request_time); 
     2118        cache->cached->compiling = XG(request_time); 
    20902119    } LEAVE_LOCK_EX(cache); 
    20912120 
    20922121    if (catched) { 
    2093         cache->compiling = 0; 
     2122        cache->cached->compiling = 0; 
    20942123        zend_bailout(); 
    20952124    } 
     
    21722201    if (xc_php_caches) { 
    21732202        for (i = 0; i < xc_php_hcache.size; i ++) { 
    2174             shm = xc_php_caches[i]->shm; 
     2203            shm = xc_php_caches[i].shm; 
    21752204            if (shm->handlers->is_readwrite(shm, p)) { 
    21762205                return 1; 
     
    21812210    if (xc_var_caches) { 
    21822211        for (i = 0; i < xc_var_hcache.size; i ++) { 
    2183             shm = xc_var_caches[i]->shm; 
     2212            shm = xc_var_caches[i].shm; 
    21842213            if (shm->handlers->is_readwrite(shm, p)) { 
    21852214                return 1; 
     
    21972226    if (xc_php_caches) { 
    21982227        for (i = 0; i < xc_php_hcache.size; i ++) { 
    2199             shm = xc_php_caches[i]->shm; 
     2228            shm = xc_php_caches[i].shm; 
    22002229            if (shm->handlers->is_readonly(shm, p)) { 
    22012230                return 1; 
     
    22062235    if (xc_var_caches) { 
    22072236        for (i = 0; i < xc_var_hcache.size; i ++) { 
    2208             shm = xc_var_caches[i]->shm; 
     2237            shm = xc_var_caches[i].shm; 
    22092238            if (shm->handlers->is_readonly(shm, p)) { 
    22102239                return 1; 
     
    22552284} 
    22562285/* }}} */ 
    2257 static xc_shm_t *xc_cache_destroy(xc_cache_t **caches, xc_hash_t *hcache) /* {{{ */ 
     2286static xc_shm_t *xc_cache_destroy(xc_cache_t *caches, xc_hash_t *hcache) /* {{{ */ 
    22582287{ 
    22592288    size_t i; 
    2260     xc_cache_t *cache; 
    22612289    xc_shm_t *shm = NULL; 
    22622290 
    2263     if (!caches) { 
    2264         return shm; 
    2265     } 
     2291    assert(caches); 
    22662292 
    22672293    for (i = 0; i < hcache->size; i ++) { 
    2268         cache = caches[i]; 
     2294        xc_cache_t *cache = &caches[i]; 
    22692295        if (cache) { 
    22702296            if (cache->lck) { 
     
    22852311} 
    22862312/* }}} */ 
    2287 static xc_cache_t **xc_cache_init(xc_shm_t *shm, xc_hash_t *hcache, xc_hash_t *hentry, xc_hash_t *hphp, xc_shmsize_t shmsize) /* {{{ */ 
    2288 { 
    2289     xc_cache_t **caches = NULL, *cache; 
     2313static xc_cache_t *xc_cache_init(xc_shm_t *shm, xc_hash_t *hcache, xc_hash_t *hentry, xc_hash_t *hphp, xc_shmsize_t shmsize) /* {{{ */ 
     2314{ 
     2315    xc_cache_t *caches = NULL; 
    22902316    xc_mem_t *mem; 
    22912317    time_t now = time(NULL); 
     
    23062332    } 
    23072333 
    2308     CHECK(caches = calloc(hcache->size, sizeof(xc_cache_t *)), "caches OOM"); 
     2334    CHECK(caches = calloc(hcache->size, sizeof(xc_cache_t)), "caches OOM"); 
    23092335 
    23102336    for (i = 0; i < hcache->size; i ++) { 
    2311         CHECK(mem            = shm->handlers->meminit(shm, memsize), "Failed init memory allocator"); 
    2312         CHECK(cache          = mem->handlers->calloc(mem, 1, sizeof(xc_cache_t)), "cache OOM"); 
    2313         CHECK(cache->entries = mem->handlers->calloc(mem, hentry->size, sizeof(xc_entry_t*)), "entries OOM"); 
     2337        xc_cache_t *cache = &caches[i]; 
     2338        CHECK(mem                     = shm->handlers->meminit(shm, memsize), "Failed init memory allocator"); 
     2339        CHECK(cache->cached           = mem->handlers->calloc(mem, 1, sizeof(xc_cached_t)), "cache OOM"); 
     2340        CHECK(cache->cached->entries  = mem->handlers->calloc(mem, hentry->size, sizeof(xc_entry_t*)), "entries OOM"); 
    23142341        if (hphp) { 
    2315             CHECK(cache->phps= mem->handlers->calloc(mem, hphp->size, sizeof(xc_entry_data_php_t*)), "phps OOM"); 
    2316         } 
    2317         CHECK(cache->lck     = xc_lock_init(NULL), "can't create lock"); 
     2342            CHECK(cache->cached->phps = mem->handlers->calloc(mem, hphp->size, sizeof(xc_entry_data_php_t*)), "phps OOM"); 
     2343        } 
     2344        CHECK(cache->lck              = xc_lock_init(NULL), "can't create lock"); 
    23182345 
    23192346        cache->hcache  = hcache; 
     
    23232350        cache->mem     = mem; 
    23242351        cache->cacheid = i; 
    2325         cache->last_gc_deletes = now; 
    2326         cache->last_gc_expires = now; 
    2327         caches[i] = cache; 
     2352        cache->cached->last_gc_deletes = now; 
     2353        cache->cached->last_gc_expires = now; 
    23282354    } 
    23292355    return caches; 
     
    25772603    ENTER_LOCK(cache) { 
    25782604        for (entryslotid = 0, c = cache->hentry->size; entryslotid < c; entryslotid ++) { 
    2579             for (e = cache->entries[entryslotid]; e; e = next) { 
     2605            for (e = cache->cached->entries[entryslotid]; e; e = next) { 
    25802606                next = e->next; 
    25812607                xc_entry_remove_unlocked(type, cache, entryslotid, e TSRMLS_CC); 
    25822608            } 
    2583             cache->entries[entryslotid] = NULL; 
     2609            cache->cached->entries[entryslotid] = NULL; 
    25842610        } 
    25852611    } LEAVE_LOCK(cache); 
     
    25912617    long type; 
    25922618    int size; 
    2593     xc_cache_t **caches, *cache; 
     2619    xc_cache_t *caches, *cache; 
    25942620    long id = 0; 
    25952621 
     
    26482674            array_init(return_value); 
    26492675 
    2650             cache = caches[id]; 
     2676            cache = &caches[id]; 
    26512677            ENTER_LOCK(cache) { 
    26522678                if (optype == XC_OP_INFO) { 
     
    26672693            if (id == -1) { 
    26682694                for (id = 0; id < size; ++id) { 
    2669                     xc_clear(type, caches[id] TSRMLS_CC); 
     2695                    xc_clear(type, &caches[id] TSRMLS_CC); 
    26702696                } 
    26712697            } 
    26722698            else { 
    2673                 xc_clear(type, caches[id] TSRMLS_CC); 
     2699                xc_clear(type, &caches[id] TSRMLS_CC); 
    26742700            } 
    26752701 
     
    27632789    } 
    27642790    xc_entry_var_init_key(&entry_var, &entry_hash, name TSRMLS_CC); 
    2765     cache = xc_var_caches[entry_hash.cacheid]; 
     2791    cache = &xc_var_caches[entry_hash.cacheid]; 
    27662792 
    27672793    ENTER_LOCK(cache) { 
     
    27702796            /* return */ 
    27712797            xc_processor_restore_zval(return_value, stored_entry_var->value, stored_entry_var->have_references TSRMLS_CC); 
    2772             xc_cache_hit_unlocked(cache TSRMLS_CC); 
     2798            xc_cached_hit_unlocked(cache->cached TSRMLS_CC); 
    27732799        } 
    27742800        else { 
     
    28092835 
    28102836    xc_entry_var_init_key(&entry_var, &entry_hash, name TSRMLS_CC); 
    2811     cache = xc_var_caches[entry_hash.cacheid]; 
     2837    cache = &xc_var_caches[entry_hash.cacheid]; 
    28122838 
    28132839    ENTER_LOCK(cache) { 
     
    28392865    } 
    28402866    xc_entry_var_init_key(&entry_var, &entry_hash, name TSRMLS_CC); 
    2841     cache = xc_var_caches[entry_hash.cacheid]; 
     2867    cache = &xc_var_caches[entry_hash.cacheid]; 
    28422868 
    28432869    ENTER_LOCK(cache) { 
    28442870        stored_entry_var = (xc_entry_var_t *) xc_entry_find_unlocked(XC_TYPE_VAR, cache, entry_hash.entryslotid, (xc_entry_t *) &entry_var TSRMLS_CC); 
    28452871        if (stored_entry_var) { 
    2846             xc_cache_hit_unlocked(cache TSRMLS_CC); 
     2872            xc_cached_hit_unlocked(cache->cached TSRMLS_CC); 
    28472873            RETVAL_TRUE; 
    28482874            /* return */ 
     
    28732899    } 
    28742900    xc_entry_var_init_key(&entry_var, &entry_hash, name TSRMLS_CC); 
    2875     cache = xc_var_caches[entry_hash.cacheid]; 
     2901    cache = &xc_var_caches[entry_hash.cacheid]; 
    28762902 
    28772903    ENTER_LOCK(cache) { 
     
    29042930 
    29052931    for (i = 0, iend = xc_var_hcache.size; i < iend; i ++) { 
    2906         xc_cache_t *cache = xc_var_caches[i]; 
     2932        xc_cache_t *cache = &xc_var_caches[i]; 
    29072933        ENTER_LOCK(cache) { 
    29082934            int entryslotid, jend; 
    29092935            for (entryslotid = 0, jend = cache->hentry->size; entryslotid < jend; entryslotid ++) { 
    29102936                xc_entry_t *entry, *next; 
    2911                 for (entry = cache->entries[entryslotid]; entry; entry = next) { 
     2937                for (entry = cache->cached->entries[entryslotid]; entry; entry = next) { 
    29122938                    next = entry->next; 
    29132939                    if (xc_entry_has_prefix_unlocked(XC_TYPE_VAR, entry, prefix)) { 
     
    29462972 
    29472973    xc_entry_var_init_key(&entry_var, &entry_hash, name TSRMLS_CC); 
    2948     cache = xc_var_caches[entry_hash.cacheid]; 
     2974    cache = &xc_var_caches[entry_hash.cacheid]; 
    29492975 
    29502976    ENTER_LOCK(cache) { 
     
    29642990                zv = (zval *) cache->shm->handlers->to_readwrite(cache->shm, (char *) stored_entry_var->value); 
    29652991                Z_LVAL_P(zv) = value; 
    2966                 ++cache->updates; 
     2992                ++cache->cached->updates; 
    29672993                break; /* leave lock */ 
    29682994            } 
     
    32083234    if (ext) { 
    32093235        /* zend_optimizer.optimization_level>0 is not compatible with other cacher, disabling */ 
     3236#if 0 
    32103237        ext->op_array_handler = NULL; 
     3238#endif 
    32113239    } 
    32123240    /* cache if there's an op_array_ctor */ 
  • trunk/xcache/xc_mem.h

    r982 r1062  
    2525#define XC_MEM_STRNDUP(func)         char *func(xc_mem_t *mem, const char *str, xc_memsize_t len) 
    2626#define XC_MEM_STRDUP(func)          char *func(xc_mem_t *mem, const char *str) 
    27 #define XC_MEM_AVAIL(func)           xc_memsize_t      func(xc_mem_t *mem) 
    28 #define XC_MEM_SIZE(func)            xc_memsize_t      func(xc_mem_t *mem) 
    29 #define XC_MEM_FREEBLOCK_FIRST(func) const xc_block_t *func(xc_mem_t *mem) 
     27#define XC_MEM_AVAIL(func)           xc_memsize_t      func(const xc_mem_t *mem) 
     28#define XC_MEM_SIZE(func)            xc_memsize_t      func(const xc_mem_t *mem) 
     29#define XC_MEM_FREEBLOCK_FIRST(func) const xc_block_t *func(const xc_mem_t *mem) 
    3030#define XC_MEM_FREEBLOCK_NEXT(func)  const xc_block_t *func(const xc_block_t *block) 
    3131#define XC_MEM_BLOCK_SIZE(func)      xc_memsize_t      func(const xc_block_t *block) 
Note: See TracChangeset for help on using the changeset viewer.