Changeset 148 in svn for trunk/xcache.c


Ignore:
Timestamp:
2006-09-09T02:56:44+02:00 (9 years ago)
Author:
Xuefer
Message:

reconstruct shm/allocator

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/xcache.c

    r146 r148  
    6868
    6969/* {{{ globals */
     70static char *xc_shm_scheme = NULL;
    7071static char *xc_mmap_path = NULL;
    7172static char *xc_coredump_dir = NULL;
     
    151152static void xc_entry_free_real_dmz(volatile xc_entry_t *xce) /* {{{ */
    152153{
    153     xc_mem_free(xce->cache->mem, (xc_entry_t *)xce);
     154    xce->cache->mem->handlers->free(xce->cache->mem, (xc_entry_t *)xce);
    154155}
    155156/* }}} */
     
    253254{
    254255    xc_entry_t *p, **pp;
    255     xc_entry_t *next;
    256256    int i, c;
    257257
     
    395395#endif
    396396    xc_mem_t *mem = cache->mem;
     397    const xc_mem_handlers_t *handlers = mem->handlers;
    397398    zend_ulong interval = (cachetype == XC_TYPE_PHP) ? xc_php_gc_interval : xc_var_gc_interval;
    398399
     
    416417    array_init(blocks);
    417418
    418     add_assoc_long_ex(return_value, ZEND_STRS("size"),  xc_mem_size(mem));
    419     add_assoc_long_ex(return_value, ZEND_STRS("avail"), xc_mem_avail(mem));
     419    add_assoc_long_ex(return_value, ZEND_STRS("size"),  handlers->size(mem));
     420    add_assoc_long_ex(return_value, ZEND_STRS("avail"), handlers->avail(mem));
    420421    add_assoc_bool_ex(return_value, ZEND_STRS("can_readonly"), xc_readonly_protection);
    421422
    422     for (b = xc_mem_freeblock_first(mem); b; b = xc_mem_freeblock_next(b)) {
     423    for (b = handlers->freeblock_first(mem); b; b = handlers->freeblock_next(b)) {
    423424        zval *bi;
    424425
     
    426427        array_init(bi);
    427428
    428         add_assoc_long_ex(bi, ZEND_STRS("size"),   xc_mem_block_size(b));
    429         add_assoc_long_ex(bi, ZEND_STRS("offset"), xc_mem_block_offset(mem, b));
     429        add_assoc_long_ex(bi, ZEND_STRS("size"),   handlers->block_size(b));
     430        add_assoc_long_ex(bi, ZEND_STRS("offset"), handlers->block_offset(mem, b));
    430431        add_next_index_zval(blocks, bi);
    431432#ifndef NDEBUG
    432         avail += xc_mem_block_size(b);
     433        avail += handlers->block_size(b);
    433434#endif
    434435    }
    435436    add_assoc_zval_ex(return_value, ZEND_STRS("free_blocks"), blocks);
    436     assert(avail == xc_mem_avail(mem));
     437    assert(avail == handlers->avail(mem));
    437438}
    438439/* }}} */
     
    10251026int xc_is_rw(const void *p) /* {{{ */
    10261027{
     1028    xc_shm_t *shm;
    10271029    int i;
    10281030    if (!xc_initized) {
     
    10301032    }
    10311033    for (i = 0; i < xc_php_hcache.size; i ++) {
    1032         if (xc_shm_is_readwrite(xc_php_caches[i]->shm, p)) {
     1034        shm = xc_php_caches[i]->shm;
     1035        if (shm->handlers->is_readwrite(shm, p)) {
    10331036            return 1;
    10341037        }
    10351038    }
    10361039    for (i = 0; i < xc_var_hcache.size; i ++) {
    1037         if (xc_shm_is_readwrite(xc_var_caches[i]->shm, p)) {
     1040        shm = xc_var_caches[i]->shm;
     1041        if (shm->handlers->is_readwrite(shm, p)) {
    10381042            return 1;
    10391043        }
     
    10441048int xc_is_ro(const void *p) /* {{{ */
    10451049{
     1050    xc_shm_t *shm;
    10461051    int i;
    10471052    if (!xc_initized) {
     
    10491054    }
    10501055    for (i = 0; i < xc_php_hcache.size; i ++) {
    1051         if (xc_shm_is_readonly(xc_php_caches[i]->shm, p)) {
     1056        shm = xc_php_caches[i]->shm;
     1057        if (shm->handlers->is_readonly(shm, p)) {
    10521058            return 1;
    10531059        }
    10541060    }
    10551061    for (i = 0; i < xc_var_hcache.size; i ++) {
    1056         if (xc_shm_is_readonly(xc_var_caches[i]->shm, p)) {
     1062        shm = xc_var_caches[i]->shm;
     1063        if (shm->handlers->is_readonly(shm, p)) {
    10571064            return 1;
    10581065        }
     
    11281135            /* do NOT free
    11291136            if (cache->entries) {
    1130                 xc_mem_free(cache->mem, cache->entries);
     1137                cache->mem->handlers->free(cache->mem, cache->entries);
    11311138            }
    1132             xc_mem_free(cache->mem, cache);
     1139            cache->mem->handlers->free(cache->mem, cache);
    11331140            */
    1134             xc_mem_destroy(cache->mem);
     1141            shm->handlers->memdestroy(cache->mem);
    11351142            shm = cache->shm;
    11361143        }
     
    11401147}
    11411148/* }}} */
    1142 static xc_cache_t **xc_cache_init(xc_shm_t *shm, char *ptr, xc_hash_t *hcache, xc_hash_t *hentry, xc_shmsize_t shmsize) /* {{{ */
     1149static xc_cache_t **xc_cache_init(xc_shm_t *shm, xc_hash_t *hcache, xc_hash_t *hentry, xc_shmsize_t shmsize) /* {{{ */
    11431150{
    11441151    xc_cache_t **caches = NULL, *cache;
     
    11641171
    11651172    for (i = 0; i < hcache->size; i ++) {
    1166         CHECK(mem            = xc_mem_init(ptr, memsize), "Failed init memory allocator");
    1167         ptr += memsize;
    1168         CHECK(cache          = xc_mem_calloc(mem, 1, sizeof(xc_cache_t)), "cache OOM");
    1169         CHECK(cache->entries = xc_mem_calloc(mem, hentry->size, sizeof(xc_entry_t*)), "entries OOM");
     1173        CHECK(mem            = shm->handlers->meminit(shm, memsize), "Failed init memory allocator");
     1174        CHECK(cache          = mem->handlers->calloc(mem, 1, sizeof(xc_cache_t)), "cache OOM");
     1175        CHECK(cache->entries = mem->handlers->calloc(mem, hentry->size, sizeof(xc_entry_t*)), "entries OOM");
    11701176        CHECK(cache->lck     = xc_lock_init(NULL), "can't create lock");
    11711177
     
    11791185        caches[i] = cache;
    11801186    }
    1181     assert(ptr <= (char*)xc_shm_ptr(shm) + shmsize);
    11821187    return caches;
    11831188
     
    12141219{
    12151220    xc_shm_t *shm;
    1216     char *ptr;
    12171221
    12181222    xc_php_caches = xc_var_caches = NULL;
    12191223
    12201224    if (xc_php_size || xc_var_size) {
    1221         CHECK(shm = xc_shm_init(xc_mmap_path, ALIGN(xc_php_size) + ALIGN(xc_var_size), xc_readonly_protection), "Cannot create shm");
    1222         if (!xc_shm_can_readonly(shm)) {
     1225        CHECK(shm = xc_shm_init(xc_shm_scheme, ALIGN(xc_php_size) + ALIGN(xc_var_size), xc_readonly_protection, xc_mmap_path, NULL), "Cannot create shm");
     1226        if (!shm->handlers->can_readonly(shm)) {
    12231227            xc_readonly_protection = 0;
    12241228        }
    12251229
    1226         ptr = (char *)xc_shm_ptr(shm);
    12271230        if (xc_php_size) {
    12281231            origin_compile_file = zend_compile_file;
    12291232            zend_compile_file = xc_compile_file;
    12301233
    1231             CHECK(xc_php_caches = xc_cache_init(shm, ptr, &xc_php_hcache, &xc_php_hentry, xc_php_size), "failed init opcode cache");
    1232             ptr += ALIGN(xc_php_size);
     1234            CHECK(xc_php_caches = xc_cache_init(shm, &xc_php_hcache, &xc_php_hentry, xc_php_size), "failed init opcode cache");
    12331235        }
    12341236
    12351237        if (xc_var_size) {
    1236             CHECK(xc_var_caches = xc_cache_init(shm, ptr, &xc_var_hcache, &xc_var_hentry, xc_var_size), "failed init variable cache");
     1238            CHECK(xc_var_caches = xc_cache_init(shm, &xc_var_hcache, &xc_var_hentry, xc_var_size), "failed init variable cache");
    12371239        }
    12381240    }
     
    21152117PHP_INI_END()
    21162118/* }}} */
    2117 static int xc_config_long_disp(char *name, char *default_value) /* {{{ */
     2119static int xc_config_string_disp(char *name, char *default_value) /* {{{ */
    21182120{
    21192121    char *value;
     
    21312133}
    21322134/* }}} */
    2133 #define xc_config_hash_disp xc_config_long_disp
     2135#define xc_config_hash_disp xc_config_string_disp
     2136#define xc_config_long_disp xc_config_string_disp
    21342137/* {{{ PHP_MINFO_FUNCTION(xcache) */
    21352138static PHP_MINFO_FUNCTION(xcache)
     
    21392142
    21402143    php_info_print_table_start();
    2141     php_info_print_table_header(2, "XCache Support", XCACHE_MODULES);
     2144    php_info_print_table_header(2, "XCache Support", "enabled");
    21422145    php_info_print_table_row(2, "Version", XCACHE_VERSION);
    21432146    php_info_print_table_row(2, "Modules Built", XCACHE_MODULES);
     
    21692172    php_info_print_table_start();
    21702173    php_info_print_table_header(2, "Directive ", "Value");
     2174    xc_config_string_disp("xcache.shm_scheme", "mmap");
    21712175    xc_config_long_disp("xcache.size",        "0");
    21722176    xc_config_hash_disp("xcache.count",       "1");
     
    22502254}
    22512255/* }}} */
     2256static int xc_config_string(char **p, char *name, char *default_value) /* {{{ */
     2257{
     2258    char *value;
     2259
     2260    if (cfg_get_string(name, &value) != SUCCESS) {
     2261        value = default_value;
     2262    }
     2263
     2264    *p = strdup(value);
     2265    return SUCCESS;
     2266}
     2267/* }}} */
    22522268/* {{{ PHP_MINIT_FUNCTION(xcache) */
    22532269static PHP_MINIT_FUNCTION(xcache)
     
    22782294    }
    22792295
     2296    xc_config_string(&xc_shm_scheme,   "xcache.shm_scheme", "mmap");
    22802297    xc_config_long(&xc_php_size,       "xcache.size",        "0");
    22812298    xc_config_hash(&xc_php_hcache,     "xcache.count",       "1");
     
    23022319
    23032320    xc_init_constant(module_number TSRMLS_CC);
     2321    xc_shm_init_modules();
    23042322
    23052323    if ((xc_php_size || xc_var_size) && xc_mmap_path && xc_mmap_path[0]) {
     
    23312349        pefree(xc_mmap_path, 1);
    23322350        xc_mmap_path = NULL;
     2351    }
     2352    if (xc_shm_scheme) {
     2353        pefree(xc_shm_scheme, 1);
     2354        xc_shm_scheme = NULL;
    23332355    }
    23342356
Note: See TracChangeset for help on using the changeset viewer.