Ignore:
Timestamp:
2012-08-09T11:04:02+02:00 (21 months ago)
Author:
moo
Message:

refactor: s/mem/allocator/

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:ignore
      •  

        old new  
        11acinclude.m4 
        22aclocal.m4 
         3allocator_test 
        34autom4te.cache 
        45build 
         
        1617conftest.c 
        1718.deps 
         19devel.fpm 
        1820devel.ini 
        1921devel.php 
        20 devel.fpm 
        2122.gdb_history 
        2223include 
  • trunk/mod_cacher/xc_cacher.c

    r1132 r1135  
    100100    struct _xc_lock_t  *lck; 
    101101    struct _xc_shm_t   *shm; /* which shm contains us */ 
    102     struct _xc_mem_t   *mem; /* which mem contains us */ 
     102    xc_allocator_t *allocator; 
    103103 
    104104    xc_hash_t  *hentry; /* hash settings to entry */ 
     
    125125static zend_ulong xc_var_gc_interval = 0; 
    126126 
     127static char *xc_php_allocator = NULL; 
     128static char *xc_var_allocator = NULL; 
     129 
    127130/* total size */ 
    128131static zend_ulong xc_php_size  = 0; 
     
    163166    php->hits     = 0; 
    164167    php->refcount = 0; 
    165     stored_php = xc_processor_store_xc_entry_data_php_t(cache->shm, cache->mem, php TSRMLS_CC); 
     168    stored_php = xc_processor_store_xc_entry_data_php_t(cache->shm, cache->allocator, php TSRMLS_CC); 
    166169    if (stored_php) { 
    167170        xc_php_add_unlocked(cache->cached, stored_php); 
     
    188191static void xc_php_free_unlocked(xc_cache_t *cache, xc_entry_data_php_t *php) /* {{{ */ 
    189192{ 
    190     cache->mem->handlers->free(cache->mem, (xc_entry_data_php_t *)php); 
     193    cache->allocator->vtable->free(cache->allocator, (xc_entry_data_php_t *)php); 
    191194} 
    192195/* }}} */ 
     
    310313    entry->atime = XG(request_time); 
    311314    stored_entry = type == XC_TYPE_PHP 
    312         ? (xc_entry_t *) xc_processor_store_xc_entry_php_t(cache->shm, cache->mem, (xc_entry_php_t *) entry TSRMLS_CC) 
    313         : (xc_entry_t *) xc_processor_store_xc_entry_var_t(cache->shm, cache->mem, (xc_entry_var_t *) entry TSRMLS_CC); 
     315        ? (xc_entry_t *) xc_processor_store_xc_entry_php_t(cache->shm, cache->allocator, (xc_entry_php_t *) entry TSRMLS_CC) 
     316        : (xc_entry_t *) xc_processor_store_xc_entry_var_t(cache->shm, cache->allocator, (xc_entry_var_t *) entry TSRMLS_CC); 
    314317    if (stored_entry) { 
    315318        xc_entry_add_unlocked(cache->cached, entryslotid, stored_entry); 
     
    338341        xc_php_release_unlocked(cache, ((xc_entry_php_t *) entry)->php); 
    339342    } 
    340     cache->mem->handlers->free(cache->mem, (xc_entry_t *)entry); 
     343    cache->allocator->vtable->free(cache->allocator, (xc_entry_t *)entry); 
    341344} 
    342345/* }}} */ 
     
    604607    zval *blocks, *hits; 
    605608    size_t i; 
    606     const xc_block_t *b; 
     609    const xc_allocator_block_t *b; 
    607610#ifndef NDEBUG 
    608611    xc_memsize_t avail = 0; 
    609612#endif 
    610     const xc_mem_t *mem = cache->mem; 
    611     const xc_mem_handlers_t *handlers = mem->handlers; 
     613    const xc_allocator_t *allocator = cache->allocator; 
     614    const xc_allocator_vtable_t *vtable = allocator->vtable; 
    612615    zend_ulong interval; 
    613616    const xc_cached_t *cached = cache->cached; 
     
    657660    array_init(blocks); 
    658661 
    659     add_assoc_long_ex(return_value, ZEND_STRS("size"),  handlers->size(mem)); 
    660     add_assoc_long_ex(return_value, ZEND_STRS("avail"), handlers->avail(mem)); 
     662    add_assoc_long_ex(return_value, ZEND_STRS("size"),  vtable->size(allocator)); 
     663    add_assoc_long_ex(return_value, ZEND_STRS("avail"), vtable->avail(allocator)); 
    661664    add_assoc_bool_ex(return_value, ZEND_STRS("can_readonly"), xc_readonly_protection); 
    662665 
    663     for (b = handlers->freeblock_first(mem); b; b = handlers->freeblock_next(b)) { 
     666    for (b = vtable->freeblock_first(allocator); b; b = vtable->freeblock_next(b)) { 
    664667        zval *bi; 
    665668 
     
    667670        array_init(bi); 
    668671 
    669         add_assoc_long_ex(bi, ZEND_STRS("size"),   handlers->block_size(b)); 
    670         add_assoc_long_ex(bi, ZEND_STRS("offset"), handlers->block_offset(mem, b)); 
     672        add_assoc_long_ex(bi, ZEND_STRS("size"),   vtable->block_size(b)); 
     673        add_assoc_long_ex(bi, ZEND_STRS("offset"), vtable->block_offset(allocator, b)); 
    671674        add_next_index_zval(blocks, bi); 
    672675#ifndef NDEBUG 
    673         avail += handlers->block_size(b); 
     676        avail += vtable->block_size(b); 
    674677#endif 
    675678    } 
    676679    add_assoc_zval_ex(return_value, ZEND_STRS("free_blocks"), blocks); 
    677680#ifndef NDEBUG 
    678     assert(avail == handlers->avail(mem)); 
     681    assert(avail == vtable->avail(allocator)); 
    679682#endif 
    680683} 
     
    23112314            /* do NOT touch cached data */ 
    23122315            shm = cache->shm; 
    2313             cache->shm->handlers->memdestroy(cache->mem); 
     2316            cache->shm->handlers->memdestroy(cache->allocator); 
    23142317        } 
    23152318    } 
     
    23182321} 
    23192322/* }}} */ 
    2320 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) /* {{{ */ 
     2323static xc_cache_t *xc_cache_init(xc_shm_t *shm, const char *allocator_name, xc_hash_t *hcache, xc_hash_t *hentry, xc_hash_t *hphp, xc_shmsize_t shmsize) /* {{{ */ 
    23212324{ 
    23222325    xc_cache_t *caches = NULL; 
    2323     xc_mem_t *mem; 
     2326    xc_allocator_t *allocator; 
    23242327    time_t now = time(NULL); 
    23252328    size_t i; 
     
    23432346    for (i = 0; i < hcache->size; i ++) { 
    23442347        xc_cache_t *cache = &caches[i]; 
    2345         CHECK(mem                     = shm->handlers->meminit(shm, memsize), "Failed init memory allocator"); 
    2346         CHECK(cache->cached           = mem->handlers->calloc(mem, 1, sizeof(xc_cached_t)), "cache OOM"); 
    2347         CHECK(cache->cached->entries  = mem->handlers->calloc(mem, hentry->size, sizeof(xc_entry_t*)), "entries OOM"); 
     2348        CHECK(allocator = shm->handlers->meminit(shm, memsize), "Failed init shm"); 
     2349        if (!(allocator->vtable = xc_allocator_find(allocator_name))) { 
     2350            zend_error(E_ERROR, "Allocator %s not found", allocator_name); 
     2351            goto err; 
     2352        } 
     2353        CHECK(allocator->vtable->init(shm, allocator, memsize), "Failed init allocator"); 
     2354        CHECK(cache->cached           = allocator->vtable->calloc(allocator, 1, sizeof(xc_cached_t)), "cache OOM"); 
     2355        CHECK(cache->cached->entries  = allocator->vtable->calloc(allocator, hentry->size, sizeof(xc_entry_t*)), "entries OOM"); 
    23482356        if (hphp) { 
    2349             CHECK(cache->cached->phps = mem->handlers->calloc(mem, hphp->size, sizeof(xc_entry_data_php_t*)), "phps OOM"); 
     2357            CHECK(cache->cached->phps = allocator->vtable->calloc(allocator, hphp->size, sizeof(xc_entry_data_php_t*)), "phps OOM"); 
    23502358        } 
    23512359        CHECK(cache->lck              = xc_lock_init(NULL), "can't create lock"); 
     
    23552363        cache->hphp    = hphp; 
    23562364        cache->shm     = shm; 
    2357         cache->mem     = mem; 
     2365        cache->allocator = allocator; 
    23582366        cache->cacheid = i; 
    23592367        cache->cached->last_gc_deletes = now; 
     
    24132421 
    24142422        if (xc_php_size) { 
    2415             CHECK(xc_php_caches = xc_cache_init(shm, &xc_php_hcache, &xc_php_hentry, &xc_php_hentry, xc_php_size), "failed init opcode cache"); 
     2423            CHECK(xc_php_caches = xc_cache_init(shm, xc_php_allocator, &xc_php_hcache, &xc_php_hentry, &xc_php_hentry, xc_php_size), "failed init opcode cache"); 
    24162424        } 
    24172425 
    24182426        if (xc_var_size) { 
    2419             CHECK(xc_var_caches = xc_cache_init(shm, &xc_var_hcache, &xc_var_hentry, NULL, xc_var_size), "failed init variable cache"); 
     2427            CHECK(xc_var_caches = xc_cache_init(shm, xc_var_allocator, &xc_var_hcache, &xc_var_hentry, NULL, xc_var_size), "failed init variable cache"); 
    24202428        } 
    24212429    } 
     
    31843192    PHP_INI_ENTRY1     ("xcache.count",                  "1", PHP_INI_SYSTEM, xcache_OnUpdateDummy,    NULL) 
    31853193    PHP_INI_ENTRY1     ("xcache.slots",                 "8K", PHP_INI_SYSTEM, xcache_OnUpdateDummy,    NULL) 
     3194    PHP_INI_ENTRY1     ("xcache.allocator",        "bestfit", PHP_INI_SYSTEM, xcache_OnUpdateString,   &xc_php_allocator) 
    31863195    PHP_INI_ENTRY1     ("xcache.ttl",                    "0", PHP_INI_SYSTEM, xcache_OnUpdateULong,    &xc_php_ttl) 
    31873196    PHP_INI_ENTRY1     ("xcache.gc_interval",            "0", PHP_INI_SYSTEM, xcache_OnUpdateULong,    &xc_php_gc_interval) 
     
    31943203    PHP_INI_ENTRY1     ("xcache.var_maxttl",             "0", PHP_INI_SYSTEM, xcache_OnUpdateULong,    &xc_var_maxttl) 
    31953204    PHP_INI_ENTRY1     ("xcache.var_gc_interval",      "120", PHP_INI_SYSTEM, xcache_OnUpdateULong,    &xc_var_gc_interval) 
     3205    PHP_INI_ENTRY1     ("xcache.var_allocator",    "bestfit", PHP_INI_SYSTEM, xcache_OnUpdateString,   &xc_var_allocator) 
    31963206    STD_PHP_INI_ENTRY  ("xcache.var_ttl",                "0", PHP_INI_ALL,    OnUpdateLong, var_ttl,   zend_xcache_globals, xcache_globals) 
    31973207PHP_INI_END() 
     
    33603370        pefree(xc_shm_scheme, 1); 
    33613371        xc_shm_scheme = NULL; 
     3372    } 
     3373    if (xc_php_allocator) { 
     3374        pefree(xc_php_allocator, 1); 
     3375        xc_php_allocator = NULL; 
     3376    } 
     3377    if (xc_var_allocator) { 
     3378        pefree(xc_var_allocator, 1); 
     3379        xc_var_allocator = NULL; 
    33623380    } 
    33633381 
Note: See TracChangeset for help on using the changeset viewer.