Changeset 1135 in svn for trunk


Ignore:
Timestamp:
2012-08-09T11:04:02+02:00 (3 years ago)
Author:
Xuefer
Message:

refactor: s/mem/allocator/

Location:
trunk
Files:
11 edited
2 moved

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/Makefile.frag.deps

    r1114 r1135  
    1 $(XCACHE_INCLUDES_I) $(builddir)/includes.lo: $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_mem.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/mod_cacher/xc_cache.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache/xc_compatibility.h
     1$(XCACHE_INCLUDES_I) $(builddir)/includes.lo: $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/mod_cacher/xc_cache.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache/xc_compatibility.h
    22$(builddir)/mod_assembler/xc_assembler.lo:
    3 $(builddir)/mod_cacher/xc_cacher.lo: $(srcdir)/mod_cacher/xc_cacher.h $(srcdir)/mod_cacher/xc_cache.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_mem.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_compatibility.h $(XCACHE_PROC_H) $(srcdir)/xcache.h $(srcdir)/mod_cacher/xc_cache.h $(srcdir)/xcache_globals.h $(srcdir)/util/xc_stack.h $(srcdir)/xcache/xc_extension.h $(srcdir)/util/xc_stack.h $(srcdir)/xcache/xc_ini.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_sandbox.h $(srcdir)/util/xc_trace.h $(srcdir)/util/xc_vector.h $(srcdir)/util/xc_align.h
    4 $(builddir)/mod_coverager/xc_coverager.lo: $(srcdir)/mod_coverager/xc_coverager.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_mem.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_extension.h $(srcdir)/util/xc_stack.h $(srcdir)/xcache/xc_ini.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/util/xc_trace.h $(srcdir)/xcache_globals.h $(srcdir)/util/xc_stack.h
     3$(builddir)/mod_cacher/xc_cacher.lo: $(srcdir)/mod_cacher/xc_cacher.h $(srcdir)/mod_cacher/xc_cache.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_compatibility.h $(XCACHE_PROC_H) $(srcdir)/xcache.h $(srcdir)/mod_cacher/xc_cache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_allocator.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache_globals.h $(srcdir)/util/xc_stack.h $(srcdir)/xcache/xc_extension.h $(srcdir)/util/xc_stack.h $(srcdir)/xcache/xc_ini.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_sandbox.h $(srcdir)/util/xc_trace.h $(srcdir)/util/xc_vector.h $(srcdir)/util/xc_align.h
     4$(builddir)/mod_coverager/xc_coverager.lo: $(srcdir)/mod_coverager/xc_coverager.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_extension.h $(srcdir)/util/xc_stack.h $(srcdir)/xcache/xc_ini.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/util/xc_trace.h $(srcdir)/xcache_globals.h $(srcdir)/util/xc_stack.h
    55$(builddir)/mod_decoder/xc_decoder.lo:
    6 $(builddir)/mod_disassembler/xc_disassembler.lo: $(srcdir)/mod_disassembler/xc_disassembler.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_mem.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_ini.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_sandbox.h $(srcdir)/xcache/xc_compatibility.h $(XCACHE_PROC_H) $(srcdir)/xcache.h $(srcdir)/mod_cacher/xc_cache.h
     6$(builddir)/mod_disassembler/xc_disassembler.lo: $(srcdir)/mod_disassembler/xc_disassembler.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_ini.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_sandbox.h $(srcdir)/xcache/xc_compatibility.h $(XCACHE_PROC_H) $(srcdir)/xcache.h $(srcdir)/mod_cacher/xc_cache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_allocator.h $(srcdir)/xcache/xc_shm.h
    77$(builddir)/mod_encoder/xc_encoder.lo:
    8 $(builddir)/mod_optimizer/xc_optimizer.lo: $(srcdir)/mod_optimizer/xc_optimizer.h $(srcdir)/xcache/xc_extension.h $(srcdir)/util/xc_stack.h $(srcdir)/xcache/xc_ini.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_mem.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/util/xc_trace.h $(srcdir)/xcache_globals.h $(srcdir)/util/xc_stack.h
     8$(builddir)/mod_optimizer/xc_optimizer.lo: $(srcdir)/mod_optimizer/xc_optimizer.h $(srcdir)/xcache/xc_extension.h $(srcdir)/util/xc_stack.h $(srcdir)/xcache/xc_ini.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/util/xc_trace.h $(srcdir)/xcache_globals.h $(srcdir)/util/xc_stack.h
    99$(builddir)/util/xc_stack.lo: $(srcdir)/util/xc_trace.h $(srcdir)/util/xc_stack.h
    1010$(builddir)/util/xc_trace.lo: $(srcdir)/util/xc_trace.h
    11 $(builddir)/xcache.lo: $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_mem.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache_globals.h $(srcdir)/util/xc_stack.h $(srcdir)/xcache/xc_extension.h $(srcdir)/util/xc_stack.h $(srcdir)/xcache/xc_ini.h $(srcdir)/xcache/xc_const_string.h $(srcdir)/xcache/xc_opcode_spec.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/util/xc_foreachcoresig.h
     11$(builddir)/xcache.lo: $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache_globals.h $(srcdir)/util/xc_stack.h $(srcdir)/xcache/xc_extension.h $(srcdir)/util/xc_stack.h $(srcdir)/xcache/xc_ini.h $(srcdir)/xcache/xc_const_string.h $(srcdir)/xcache/xc_opcode_spec.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/util/xc_foreachcoresig.h
     12$(builddir)/xcache/xc_allocator_bestfit.lo: $(srcdir)/xcache/xc_allocator.h $(srcdir)/xcache/xc_shm.h $(srcdir)/util/xc_align.h $(srcdir)/util/xc_trace.h
     13$(builddir)/xcache/xc_allocator.lo: $(srcdir)/xcache/xc_allocator.h $(srcdir)/xcache/xc_shm.h
    1214$(builddir)/xcache/xc_compatibility.lo: $(srcdir)/xcache/xc_compatibility.h
    13 $(builddir)/xcache/xc_const_string.lo: $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_mem.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_const_string.h $(srcdir)/xcache/xc_const_string_opcodes_php5.4.h
    14 $(builddir)/xcache/xc_extension.lo: $(srcdir)/xcache/xc_extension.h $(srcdir)/util/xc_stack.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_mem.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/util/xc_trace.h
     15$(builddir)/xcache/xc_const_string.lo: $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_const_string.h $(srcdir)/xcache/xc_const_string_opcodes_php5.4.h
     16$(builddir)/xcache/xc_extension.lo: $(srcdir)/xcache/xc_extension.h $(srcdir)/util/xc_stack.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/util/xc_trace.h
    1517$(builddir)/xcache/xc_ini.lo: $(srcdir)/xcache/xc_ini.h
    16 $(builddir)/xcache/xc_lock.lo: $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_mem.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h
    17 $(builddir)/xcache/xc_malloc.lo: $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_mem.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/util/xc_align.h
    18 $(builddir)/xcache/xc_mem.lo: $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_mem.h $(srcdir)/util/xc_align.h $(srcdir)/util/xc_trace.h
    19 $(builddir)/xcache/xc_opcode_spec.lo: $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_mem.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_opcode_spec.h $(srcdir)/xcache/xc_const_string.h $(srcdir)/xcache/xc_opcode_spec_def.h
    20 $(builddir)/xcache/xc_processor.lo: $(XCACHE_PROC_C) $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_mem.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/mod_cacher/xc_cache.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/util/xc_align.h $(srcdir)/xcache/xc_const_string.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache/xc_compatibility.h $(XCACHE_PROC_H) $(srcdir)/xcache_globals.h $(srcdir)/util/xc_stack.h
    21 $(builddir)/xcache/xc_sandbox.lo: $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_mem.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_sandbox.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache_globals.h $(srcdir)/util/xc_stack.h
    22 $(builddir)/xcache/xc_shm.lo: $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_mem.h
    23 $(builddir)/xcache/xc_shm_mmap.lo: $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_mem.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_compatibility.h
    24 $(builddir)/xcache/xc_utils.lo: $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_mem.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache_globals.h $(srcdir)/util/xc_stack.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_opcode_spec.h $(srcdir)/util/xc_trace.h
     18$(builddir)/xcache/xc_lock.lo: $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h
     19$(builddir)/xcache/xc_malloc.lo: $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_allocator.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/util/xc_align.h
     20$(builddir)/xcache/xc_opcode_spec.lo: $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_opcode_spec.h $(srcdir)/xcache/xc_const_string.h $(srcdir)/xcache/xc_opcode_spec_def.h
     21$(builddir)/xcache/xc_processor.lo: $(XCACHE_PROC_C) $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/mod_cacher/xc_cache.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_allocator.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_const_string.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/util/xc_align.h $(XCACHE_PROC_H) $(srcdir)/xcache_globals.h $(srcdir)/util/xc_stack.h
     22$(builddir)/xcache/xc_sandbox.lo: $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_sandbox.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache_globals.h $(srcdir)/util/xc_stack.h
     23$(builddir)/xcache/xc_shm.lo: $(srcdir)/xcache/xc_shm.h
     24$(builddir)/xcache/xc_shm_mmap.lo: $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_compatibility.h
     25$(builddir)/xcache/xc_utils.lo: $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache_globals.h $(srcdir)/util/xc_stack.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_opcode_spec.h $(srcdir)/util/xc_trace.h
  • trunk/config.m4

    r1040 r1135  
    3232done
    3333  for i in \
     34xc_allocator.c \
     35xc_allocator_bestfit.c \
    3436xc_compatibility.c \
    3537xc_const_string.c \
     
    3739xc_ini.c \
    3840xc_lock.c \
    39 xc_mem.c \
    4041xc_opcode_spec.c \
    4142xc_processor.c \
  • trunk/config.w32

    r1108 r1135  
    1919
    2020    ADD_SOURCES(configure_module_dirname + "/xcache", " \
     21xc_allocator.c \
     22xc_allocator_bestfit.c \
    2123xc_compatibility.c \
    2224xc_const_string.c \
     
    2426xc_ini.c \
    2527xc_lock.c \
    26 xc_mem.c \
    2728xc_opcode_spec.c \
    2829xc_processor.c \
  • trunk/devel/test.mak

    r998 r1135  
    11#! /usr/bin/make -f
    22
    3 EXES=mem_test
    4 OBJS=mem.o
     3EXES=allocator_test
     4OBJS=allocator.o
    55CC=gcc
    6 CFLAGS=-g -O0 -I. -D TEST -Wall
     6CFLAGS=-g -O0 -I. -D TEST -D HAVE_XCACHE_TEST -Wall
    77TEST=valgrind
    88
    9 all: mem
     9all: allocator
    1010
    11 mem_test: xcache/xc_mem.c xcache/xc_mem.h util/xc_trace.c util/xc_trace.h
    12     $(CC) $(CFLAGS) -o mem_test xcache/xc_mem.c util/xc_trace.c
     11allocator_test: xcache/xc_allocator.h xcache/xc_allocator.c xcache/xc_malloc.c xcache/xc_allocator_bestfit.c util/xc_trace.c util/xc_trace.h
     12    $(CC) $(CFLAGS) -o allocator_test xcache/xc_allocator.c xcache/xc_malloc.c xcache/xc_allocator_bestfit.c util/xc_trace.c
    1313   
    14 mem: mem_test
    15     $(TEST) ./mem_test
     14allocator: allocator_test
     15    $(TEST) ./allocator_test
    1616
    1717clean:
  • 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
  • trunk/processor/head.m4

    r1132 r1135  
    1414/* export: #include "mod_cacher/xc_cache.h" :export */
    1515#include "mod_cacher/xc_cache.h"
    16 #include "util/xc_align.h"
     16/* export: #include "xcache/xc_shm.h" :export */
     17#include "xcache/xc_shm.h"
     18/* export: #include "xcache/xc_allocator.h" :export */
     19#include "xcache/xc_allocator.h"
    1720#include "xcache/xc_const_string.h"
    1821#include "xcache/xc_utils.h"
     22#include "util/xc_align.h"
    1923#include "xc_processor.h"
    2024#include "xcache_globals.h"
     
    9599    const xc_entry_data_php_t *php_dst;
    96100    xc_shm_t                  *shm;
    97     xc_mem_t                  *mem;
     101    xc_allocator_t            *allocator;
    98102    const zend_class_entry *cache_ce;
    99103    zend_uint cache_class_index;
     
    395399dnl ================ export API
    396400define(`DEFINE_STORE_API', `
    397 /* export: $1 *xc_processor_store_$1(xc_shm_t *shm, xc_mem_t *mem, $1 *src TSRMLS_DC); :export {{{ */
    398 $1 *xc_processor_store_$1(xc_shm_t *shm, xc_mem_t *mem, $1 *src TSRMLS_DC) {
     401/* export: $1 *xc_processor_store_$1(xc_shm_t *shm, xc_allocator_t *allocator, $1 *src TSRMLS_DC); :export {{{ */
     402$1 *xc_processor_store_$1(xc_shm_t *shm, xc_allocator_t *allocator, $1 *src TSRMLS_DC) {
    399403    $1 *dst;
    400404    xc_processor_t processor;
     
    403407    processor.reference = 1;
    404408    processor.shm = shm;
    405     processor.mem = mem;
     409    processor.allocator = allocator;
    406410
    407411    IFAUTOCHECK(`xc_stack_init(&processor.allocsizes);')
     
    440444        }
    441445
    442         /* mem :) */
    443         processor.p = (char *) processor.mem->handlers->malloc(processor.mem, processor.size);
     446        /* allocator :) */
     447        processor.p = (char *) processor.allocator->vtable->malloc(processor.allocator, processor.size);
    444448        if (processor.p == NULL) {
    445449            dst = NULL;
  • trunk/xcache/xc_allocator.c

    r1127 r1135  
    1 #ifdef TEST
    2 #   include <limits.h>
    3 #   include <stdio.h>
    4 #   define XCACHE_DEBUG
    5 typedef int zend_bool;
    6 #   define ZEND_ATTRIBUTE_PTR_FORMAT(a, b, c)
    7 #   define zend_error(type, error) fprintf(stderr, "%s", error)
    8 #else
    9 #   include <php.h>
     1#include "xc_allocator.h"
     2#include <string.h>
     3#include <stdio.h>
     4
     5typedef struct {
     6    const char *name;
     7    const xc_allocator_vtable_t *allocator_vtable;
     8} xc_allocator_info_t;
     9static xc_allocator_info_t xc_allocator_infos[10];
     10
     11int xc_allocator_register(const char *name, const xc_allocator_vtable_t *allocator_vtable) /* {{{ */
     12{
     13    size_t i;
     14    for (i = 0; i < sizeof(xc_allocator_infos) / sizeof(xc_allocator_infos[0]); i ++) {
     15        if (!xc_allocator_infos[i].name) {
     16            xc_allocator_infos[i].name = name;
     17            xc_allocator_infos[i].allocator_vtable = allocator_vtable;
     18            return 1;
     19        }
     20    }
     21    return 0;
     22}
     23/* }}} */
     24const xc_allocator_vtable_t *xc_allocator_find(const char *name) /* {{{ */
     25{
     26    size_t i;
     27    for (i = 0; i < sizeof(xc_allocator_infos) / sizeof(xc_allocator_infos[0]) && xc_allocator_infos[i].name; i ++) {
     28        if (strcmp(xc_allocator_infos[i].name, name) == 0) {
     29            return xc_allocator_infos[i].allocator_vtable;
     30        }
     31    }
     32    return NULL;
     33}
     34/* }}} */
     35void xc_allocator_init() /* {{{ */
     36{
     37    extern void xc_allocator_bestfit_register();
     38#ifdef HAVE_XCACHE_TEST
     39    extern void xc_allocator_malloc_register();
    1040#endif
    1141
    12 #ifdef XCACHE_DEBUG
    13 #   define ALLOC_DEBUG_BLOCK_CHECK
     42    memset(xc_allocator_infos, 0, sizeof(xc_allocator_infos));
     43    xc_allocator_bestfit_register();
     44#ifdef HAVE_XCACHE_TEST
     45    xc_allocator_malloc_register();
    1446#endif
    15 
    16 
    17 #include <assert.h>
    18 #include <stdlib.h>
    19 #include <string.h>
    20 #define XC_MEMBLOCK_IMPL _xc_mem_block_t
    21 #define XC_MEM_IMPL _xc_mem_mem_t
    22 #include "xc_shm.h"
    23 #include "util/xc_align.h"
    24 #include "util/xc_trace.h"
    25 
    26 #if 0
    27 #undef ALLOC_DEBUG_BLOCK_CHECK
    28 #endif
    29 
    30 #define CHAR_PTR(p) ((char *) (p))
    31 #define PADD(p, a) (CHAR_PTR(p) + a)
    32 #define PSUB(p1, p2) (CHAR_PTR(p1) - CHAR_PTR(p2))
    33 
    34 /* {{{ mem */
    35 struct _xc_mem_block_t {
    36 #ifdef ALLOC_DEBUG_BLOCK_CHECK
    37     unsigned int magic;
    38 #endif
    39     xc_memsize_t size; /* reserved even after alloc */
    40     xc_block_t *next;  /* not used after alloc */
    41 };
    42 
    43 struct _xc_mem_mem_t {
    44     const xc_mem_handlers_t *handlers;
    45     xc_shm_t                *shm;
    46     xc_memsize_t size;
    47     xc_memsize_t avail;       /* total free */
    48     xc_block_t headblock[1];  /* just as a pointer to first block*/
    49 };
    50 
    51 #ifndef XtOffsetOf
    52 #   include <linux/stddef.h>
    53 #   define XtOffsetOf(s_type, field) offsetof(s_type, field)
    54 #endif
    55 
    56 #define SizeOf(type, field) sizeof( ((type *) 0)->field )
    57 #define BLOCK_HEADER_SIZE() (ALIGN( XtOffsetOf(xc_block_t, size) + SizeOf(xc_block_t, size) ))
    58 
    59 #define BLOCK_MAGIC ((unsigned int) 0x87655678)
    60 
    61 /* }}} */
    62 static inline void xc_block_setup(xc_block_t *b, xc_memsize_t size, xc_block_t *next) /* {{{ */
    63 {
    64 #ifdef ALLOC_DEBUG_BLOCK_CHECK
    65     b->magic = BLOCK_MAGIC;
    66 #endif
    67     b->size = size;
    68     b->next = next;
    6947}
    7048/* }}} */
    71 #ifdef ALLOC_DEBUG_BLOCK_CHECK
    72 static void xc_block_check(xc_block_t *b) /* {{{ */
    73 {
    74     if (b->magic != BLOCK_MAGIC) {
    75         fprintf(stderr, "0x%X != 0x%X magic wrong \n", b->magic, BLOCK_MAGIC);
    76     }
    77 }
    78 /* }}} */
    79 #else
    80 #   define xc_block_check(b) do { } while(0)
    81 #endif
    82 
    83 
    84 static XC_MEM_MALLOC(xc_mem_malloc) /* {{{ */
    85 {
    86     xc_block_t *prev, *cur;
    87     xc_block_t *newb, *b;
    88     xc_memsize_t realsize;
    89     xc_memsize_t minsize;
    90     void *p;
    91     /* [xc_block_t:size|size] */
    92     realsize = BLOCK_HEADER_SIZE() + size;
    93     /* realsize is ALIGNed so next block start at ALIGNed address */
    94     realsize = ALIGN(realsize);
    95 
    96     TRACE("avail: %lu (%luKB). Allocate size: %lu realsize: %lu (%luKB)"
    97             , mem->avail, mem->avail / 1024
    98             , size
    99             , realsize, realsize / 1024
    100             );
    101     do {
    102         p = NULL;
    103         if (mem->avail < realsize) {
    104             TRACE("%s", " oom");
    105             break;
    106         }
    107 
    108         b = NULL;
    109         minsize = ULONG_MAX;
    110 
    111         /* prev|cur */
    112 
    113         for (prev = mem->headblock; prev->next; prev = cur) {
    114             /* while (prev->next != 0) { */
    115             cur = prev->next;
    116             xc_block_check(cur);
    117             if (cur->size == realsize) {
    118                 /* found a perfect fit, stop searching */
    119                 b = prev;
    120                 break;
    121             }
    122             /* make sure we can split on the block */
    123             else if (cur->size > (sizeof(xc_block_t) + realsize) &&
    124                     cur->size < minsize) {
    125                 /* cur is acceptable and memller */
    126                 b = prev;
    127                 minsize = cur->size;
    128             }
    129             prev = cur;
    130         }
    131 
    132         if (b == NULL) {
    133             TRACE("%s", " no fit chunk");
    134             break;
    135         }
    136 
    137         prev = b;
    138 
    139         cur = prev->next;
    140         p = PADD(cur, BLOCK_HEADER_SIZE());
    141 
    142         /* update the block header */
    143         mem->avail -= realsize;
    144 
    145         /* perfect fit, just unlink */
    146         if (cur->size == realsize) {
    147             prev->next = cur->next;
    148             TRACE(" perfect fit. Got: %p", p);
    149             break;
    150         }
    151 
    152         /* make new free block after alloced space */
    153 
    154         /* save, as it might be overwrited by newb (cur->size is ok) */
    155         b = cur->next;
    156 
    157         /* prev|cur     |next=b */
    158 
    159         newb = (xc_block_t *)PADD(cur, realsize);
    160         xc_block_setup(newb, cur->size - realsize, b);
    161         cur->size = realsize;
    162         /* prev|cur|newb|next
    163          *            `--^
    164          */
    165 
    166         TRACE(" -> avail: %lu (%luKB). new next: %p offset: %lu %luKB. Got: %p"
    167                 , mem->avail, mem->avail / 1024
    168                 , newb
    169                 , PSUB(newb, mem), PSUB(newb, mem) / 1024
    170                 , p
    171                 );
    172         prev->next = newb;
    173         /* prev|cur|newb|next
    174          *    `-----^
    175          */
    176 
    177     } while (0);
    178 
    179     return p;
    180 }
    181 /* }}} */
    182 static XC_MEM_FREE(xc_mem_free) /* {{{ return block size freed */
    183 {
    184     xc_block_t *cur, *b;
    185     int size;
    186 
    187     cur = (xc_block_t *) (CHAR_PTR(p) - BLOCK_HEADER_SIZE());
    188     TRACE("freeing: %p, size=%lu", p, cur->size);
    189     xc_block_check(cur);
    190     assert((char*)mem < (char*)cur && (char*)cur < (char*)mem + mem->size);
    191 
    192     /* find free block right before the p */
    193     b = mem->headblock;
    194     while (b->next != 0 && b->next < cur) {
    195         b = b->next;
    196     }
    197 
    198     /* restore block */
    199     cur->next = b->next;
    200     b->next = cur;
    201     size = cur->size;
    202 
    203     TRACE(" avail %lu (%luKB)", mem->avail, mem->avail / 1024);
    204     mem->avail += size;
    205 
    206     /* combine prev|cur */
    207     if (PADD(b, b->size) == (char *)cur) {
    208         b->size += cur->size;
    209         b->next = cur->next;
    210         cur = b;
    211         TRACE("%s", " combine prev");
    212     }
    213 
    214     /* combine cur|next */
    215     b = cur->next;
    216     if (PADD(cur, cur->size) == (char *)b) {
    217         cur->size += b->size;
    218         cur->next = b->next;
    219         TRACE("%s", " combine next");
    220     }
    221     TRACE(" -> avail %lu (%luKB)", mem->avail, mem->avail / 1024);
    222     return size;
    223 }
    224 /* }}} */
    225 static XC_MEM_CALLOC(xc_mem_calloc) /* {{{ */
    226 {
    227     xc_memsize_t realsize = memb * size;
    228     void *p = xc_mem_malloc(mem, realsize);
    229 
    230     if (p) {
    231         memset(p, 0, realsize);
    232     }
    233     return p;
    234 }
    235 /* }}} */
    236 static XC_MEM_REALLOC(xc_mem_realloc) /* {{{ */
    237 {
    238     void *newp = xc_mem_malloc(mem, size);
    239     if (p && newp) {
    240         memcpy(newp, p, size);
    241         xc_mem_free(mem, p);
    242     }
    243     return newp;
    244 }
    245 /* }}} */
    246 static XC_MEM_STRNDUP(xc_mem_strndup) /* {{{ */
    247 {
    248     void *p = xc_mem_malloc(mem, len + 1);
    249     if (p) {
    250         memcpy(p, str, len + 1);
    251     }
    252     return p;
    253 }
    254 /* }}} */
    255 static XC_MEM_STRDUP(xc_mem_strdup) /* {{{ */
    256 {
    257     return xc_mem_strndup(mem, str, strlen(str));
    258 }
    259 /* }}} */
    260 
    261 static XC_MEM_AVAIL(xc_mem_avail) /* {{{ */
    262 {
    263     return mem->avail;
    264 }
    265 /* }}} */
    266 static XC_MEM_SIZE(xc_mem_size) /* {{{ */
    267 {
    268     return mem->size;
    269 }
    270 /* }}} */
    271 
    272 static XC_MEM_FREEBLOCK_FIRST(xc_mem_freeblock_first) /* {{{ */
    273 {
    274     return mem->headblock->next;
    275 }
    276 /* }}} */
    277 XC_MEM_FREEBLOCK_NEXT(xc_mem_freeblock_next) /* {{{ */
    278 {
    279     return block->next;
    280 }
    281 /* }}} */
    282 XC_MEM_BLOCK_SIZE(xc_mem_block_size) /* {{{ */
    283 {
    284     return block->size;
    285 }
    286 /* }}} */
    287 XC_MEM_BLOCK_OFFSET(xc_mem_block_offset) /* {{{ */
    288 {
    289     return ((char *) block) - ((char *) mem);
    290 }
    291 /* }}} */
    292 
    293 static XC_MEM_INIT(xc_mem_init) /* {{{ */
    294 {
    295     xc_block_t *b;
    296 #define MINSIZE (ALIGN(sizeof(xc_mem_t)) + sizeof(xc_block_t))
    297     /* requires at least the header and 1 tail block */
    298     if (size < MINSIZE) {
    299         fprintf(stderr, "xc_mem_init requires %lu bytes at least\n", (unsigned long) MINSIZE);
    300         return NULL;
    301     }
    302     TRACE("size=%lu", size);
    303     mem->shm = shm;
    304     mem->size = size;
    305     mem->avail = size - MINSIZE;
    306 
    307     /* pointer to first block, right after ALIGNed header */
    308     b = mem->headblock;
    309     xc_block_setup(b, 0, (xc_block_t *) PADD(mem, ALIGN(sizeof(xc_mem_t))));
    310 
    311     /* first block*/
    312     b = b->next;
    313     xc_block_setup(b, mem->avail, 0);
    314 #undef MINSIZE
    315 
    316     return mem;
    317 }
    318 /* }}} */
    319 static XC_MEM_DESTROY(xc_mem_destroy) /* {{{ */
    320 {
    321 }
    322 /* }}} */
    323 
    32449#ifdef TEST
    32550/* {{{ testing */
     
    33358#include <time.h>
    33459
    335 int main()
     60int testAllocator(const xc_allocator_vtable_t *allocator_vtable)
    33661{
    33762    int count = 0;
    33863    void *p;
     64    xc_allocator_t *allocator;
    33965    void *memory;
    340     xc_mem_t *mem;
    34166    void **ptrs;
    34267    int size, i;
     
    35075    CHECK(memory = malloc(size), "OOM");
    35176    CHECK(ptrs   = malloc(size * sizeof(void *)), "OOM");
    352     mem = (xc_mem_t *) memory;
    353     CHECK(mem    = xc_mem_init(NULL, mem, size), "Failed init memory allocator");
     77    allocator = (xc_allocator_t *) memory;
     78    allocator->vtable = allocator_vtable;
     79    CHECK(allocator = allocator->vtable->init(NULL, allocator, size), "Failed init memory allocator");
    35480
    355     while ((p = xc_mem_malloc(mem, 1))) {
     81    while ((p = allocator->vtable->malloc(allocator, 1))) {
    35682        ptrs[count ++] = p;
    35783    }
     
    36187        i = (random() % count);
    36288        fprintf(stderr, "freeing %d: ", i);
    363         xc_mem_free(mem, ptrs[i]);
     89        allocator->vtable->free(allocator, ptrs[i]);
    36490        ptrs[i] = ptrs[count - 1];
    36591        count --;
     
    37197}
    37298/* }}} */
    373 #endif
    374 
    375 typedef struct {
    376     const char              *name;
    377     const xc_mem_handlers_t *handlers;
    378 } xc_mem_scheme_t;
    379 static xc_mem_scheme_t xc_mem_schemes[10];
    380 
    381 int xc_mem_scheme_register(const char *name, const xc_mem_handlers_t *handlers) /* {{{ */
     99int main() /* {{{ */
    382100{
    383101    int i;
    384     for (i = 0; i < 10; i ++) {
    385         if (!xc_mem_schemes[i].name) {
    386             xc_mem_schemes[i].name = name;
    387             xc_mem_schemes[i].handlers = handlers;
    388             return 1;
    389         }
     102
     103    xc_allocator_init();
     104
     105    for (i = 0; i < sizeof(xc_allocator_infos) / sizeof(xc_allocator_infos[0]) && xc_allocator_infos[i].name; i ++) {
     106        fprintf(stderr, "testing %s...\n", xc_allocator_infos[i].name);
     107        testAllocator(xc_allocator_infos[i].allocator_vtable);
    390108    }
    391109    return 0;
    392110}
    393111/* }}} */
    394 const xc_mem_handlers_t *xc_mem_scheme_find(const char *name) /* {{{ */
    395 {
    396     int i;
    397     for (i = 0; i < 10 && xc_mem_schemes[i].name; i ++) {
    398         if (strcmp(xc_mem_schemes[i].name, name) == 0) {
    399             return xc_mem_schemes[i].handlers;
    400         }
    401     }
    402     return NULL;
    403 }
    404 /* }}} */
    405 
    406 static xc_mem_handlers_t xc_mem_mem_handlers = XC_MEM_HANDLERS(mem);
    407 void xc_shm_mem_init() /* {{{ */
    408 {
    409     memset(xc_mem_schemes, 0, sizeof(xc_mem_schemes));
    410 
    411     if (xc_mem_scheme_register("mem", &xc_mem_mem_handlers) == 0) {
    412         zend_error(E_ERROR, "XCache: failed to register mem mem_scheme");
    413     }
    414 }
    415 /* }}} */
     112#endif
  • trunk/xcache/xc_allocator.h

    r1127 r1135  
     1#ifndef XC_ALLOCATOR_H_155E773CA8AFC18F3CCCDCF0831EE41D
     2#define XC_ALLOCATOR_H_155E773CA8AFC18F3CCCDCF0831EE41D
     3
     4#if _MSC_VER > 1000
     5#pragma once
     6#endif /* _MSC_VER > 1000 */
     7
    18#include "xc_shm.h"
    29
    3 typedef struct _xc_mem_handlers_t xc_mem_handlers_t;
     10typedef struct _xc_allocator_vtable_t xc_allocator_vtable_t;
    411
    5 #ifndef XC_MEM_IMPL
    6 struct _xc_mem_t {
    7     const xc_mem_handlers_t *handlers;
    8     xc_shm_t                *shm;
     12#ifndef _xc_allocator_t
     13struct _xc_allocator_t {
     14    const xc_allocator_vtable_t *vtable;
     15    xc_shm_t *shm;
    916};
    10 #   define XC_MEM_IMPL _xc_mem_t
    1117#endif
    1218
    13 #ifndef XC_MEMBLOCK_IMPL
    14 #   define XC_MEMBLOCK_IMPL _xc_block_t
    15 #endif
    16 typedef struct XC_MEM_IMPL xc_mem_t;
    17 typedef struct XC_MEMBLOCK_IMPL xc_block_t;
     19typedef struct _xc_allocator_t xc_allocator_t;
     20typedef struct _xc_allocator_block_t xc_allocator_block_t;
    1821typedef xc_shmsize_t xc_memsize_t;
    1922
    20 /* shm::mem */
    21 #define XC_MEM_MALLOC(func)          void *func(xc_mem_t *mem, xc_memsize_t size)
    22 #define XC_MEM_FREE(func)            xc_memsize_t  func(xc_mem_t *mem, const void *p)
    23 #define XC_MEM_CALLOC(func)          void *func(xc_mem_t *mem, xc_memsize_t memb, xc_memsize_t size)
    24 #define XC_MEM_REALLOC(func)         void *func(xc_mem_t *mem, const void *p, xc_memsize_t size)
    25 #define XC_MEM_STRNDUP(func)         char *func(xc_mem_t *mem, const char *str, xc_memsize_t len)
    26 #define XC_MEM_STRDUP(func)          char *func(xc_mem_t *mem, const char *str)
    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)
    30 #define XC_MEM_FREEBLOCK_NEXT(func)  const xc_block_t *func(const xc_block_t *block)
    31 #define XC_MEM_BLOCK_SIZE(func)      xc_memsize_t      func(const xc_block_t *block)
    32 #define XC_MEM_BLOCK_OFFSET(func)    xc_memsize_t      func(const xc_mem_t *mem, const xc_block_t *block)
     23/* allocator */
     24#define XC_ALLOCATOR_MALLOC(func)          void *func(xc_allocator_t *allocator, xc_memsize_t size)
     25#define XC_ALLOCATOR_FREE(func)            xc_memsize_t  func(xc_allocator_t *allocator, const void *p)
     26#define XC_ALLOCATOR_CALLOC(func)          void *func(xc_allocator_t *allocator, xc_memsize_t memb, xc_memsize_t size)
     27#define XC_ALLOCATOR_REALLOC(func)         void *func(xc_allocator_t *allocator, const void *p, xc_memsize_t size)
     28#define XC_ALLOCATOR_AVAIL(func)           xc_memsize_t      func(const xc_allocator_t *allocator)
     29#define XC_ALLOCATOR_SIZE(func)            xc_memsize_t      func(const xc_allocator_t *allocator)
     30#define XC_ALLOCATOR_FREEBLOCK_FIRST(func) const xc_allocator_block_t *func(const xc_allocator_t *allocator)
     31#define XC_ALLOCATOR_FREEBLOCK_NEXT(func)  const xc_allocator_block_t *func(const xc_allocator_block_t *block)
     32#define XC_ALLOCATOR_BLOCK_SIZE(func)      xc_memsize_t      func(const xc_allocator_block_t *block)
     33#define XC_ALLOCATOR_BLOCK_OFFSET(func)    xc_memsize_t      func(const xc_allocator_t *allocator, const xc_allocator_block_t *block)
    3334
    34 #define XC_MEM_INIT(func)            xc_mem_t *func(xc_shm_t *shm, xc_mem_t *mem, xc_memsize_t size)
    35 #define XC_MEM_DESTROY(func)         void func(xc_mem_t *mem)
     35#define XC_ALLOCATOR_INIT(func)            xc_allocator_t *func(xc_shm_t *shm, xc_allocator_t *allocator, xc_memsize_t size)
     36#define XC_ALLOCATOR_DESTROY(func)         void func(xc_allocator_t *allocator)
    3637
    37 #define XC_MEM_HANDLERS(name)   {  \
     38#define XC_ALLOCATOR_VTABLE(name)   {  \
    3839    xc_##name##_malloc             \
    3940    , xc_##name##_free             \
    4041    , xc_##name##_calloc           \
    4142    , xc_##name##_realloc          \
    42     , xc_##name##_strndup          \
    43     , xc_##name##_strdup           \
    4443    , xc_##name##_avail            \
    4544    , xc_##name##_size             \
     
    5352}
    5453
    55 struct _xc_mem_handlers_t {
    56     XC_MEM_MALLOC((*malloc));
    57     XC_MEM_FREE((*free));
    58     XC_MEM_CALLOC((*calloc));
    59     XC_MEM_REALLOC((*realloc));
    60     XC_MEM_STRNDUP((*strndup));
    61     XC_MEM_STRDUP((*strdup));
    62     XC_MEM_AVAIL((*avail));
    63     XC_MEM_SIZE((*size));
    64     XC_MEM_FREEBLOCK_FIRST((*freeblock_first));
    65     XC_MEM_FREEBLOCK_NEXT((*freeblock_next));
    66     XC_MEM_BLOCK_SIZE((*block_size));
    67     XC_MEM_BLOCK_OFFSET((*block_offset));
     54struct _xc_allocator_vtable_t {
     55    XC_ALLOCATOR_MALLOC((*malloc));
     56    XC_ALLOCATOR_FREE((*free));
     57    XC_ALLOCATOR_CALLOC((*calloc));
     58    XC_ALLOCATOR_REALLOC((*realloc));
     59    XC_ALLOCATOR_AVAIL((*avail));
     60    XC_ALLOCATOR_SIZE((*size));
     61    XC_ALLOCATOR_FREEBLOCK_FIRST((*freeblock_first));
     62    XC_ALLOCATOR_FREEBLOCK_NEXT((*freeblock_next));
     63    XC_ALLOCATOR_BLOCK_SIZE((*block_size));
     64    XC_ALLOCATOR_BLOCK_OFFSET((*block_offset));
    6865
    69     XC_MEM_INIT((*init));
    70     XC_MEM_DESTROY((*destroy));
     66    XC_ALLOCATOR_INIT((*init));
     67    XC_ALLOCATOR_DESTROY((*destroy));
    7168};
    7269
    73 int xc_mem_scheme_register(const char *name, const xc_mem_handlers_t *handlers);
    74 const xc_mem_handlers_t *xc_mem_scheme_find(const char *name);
     70int xc_allocator_register(const char *name, const xc_allocator_vtable_t *allocator_vtable);
     71const xc_allocator_vtable_t *xc_allocator_find(const char *name);
     72
     73#endif /* XC_ALLOCATOR_H_155E773CA8AFC18F3CCCDCF0831EE41D */
  • trunk/xcache/xc_malloc.c

    r1129 r1135  
    11#define XC_SHM_IMPL _xc_malloc_shm_t
    2 #define XC_MEM_IMPL _xc_malloc_mem_t
     2#define _xc_allocator_t _xc_allocator_malloc_t
    33#include <stdlib.h>
    44#include <stdio.h>
     
    99#endif
    1010#include "xc_shm.h"
    11 #include "php.h"
    12 #include "xc_utils.h"
     11#include "xc_allocator.h"
     12#ifndef TEST
     13#include "xcache.h"
     14#endif
    1315#include "util/xc_align.h"
    1416
    15 struct _xc_malloc_mem_t {
    16     const xc_mem_handlers_t *handlers;
    17     xc_shm_t                *shm;
     17struct _xc_allocator_malloc_t {
     18    const xc_allocator_vtable_t *vtable;
     19    xc_shm_t *shm;
    1820    xc_memsize_t size;
    1921    xc_memsize_t avail;       /* total free */
     
    2527    xc_shmsize_t       size;
    2628    xc_shmsize_t       memoffset;
     29#ifndef TEST
    2730    HashTable blocks;
     31#endif
    2832};
    2933/* }}} */
    3034
    31 #define CHECK(x, e) do { if ((x) == NULL) { zend_error(E_ERROR, "XCache: " e); goto err; } } while (0)
    32 
    33 static void *xc_add_to_blocks(xc_mem_t *mem, void *p, size_t size) /* {{{ */
     35#ifndef TEST
     36#   define CHECK(x, e) do { if ((x) == NULL) { zend_error(E_ERROR, "XCache: " e); goto err; } } while (0)
     37#else
     38#   define CHECK(x, e) do { if ((x) == NULL) { fprintf(stderr, "%s\n", "XCache: " e); goto err; } } while (0)
     39#endif
     40
     41static void *xc_add_to_blocks(xc_allocator_t *allocator, void *p, size_t size) /* {{{ */
    3442{
    3543    if (p) {
    36         zend_hash_add(&mem->shm->blocks, (void *) &p, sizeof(p), (void *) &size, sizeof(size), NULL);
     44#ifdef TEST
     45        allocator->avail -= size;
     46#else
     47        zend_hash_add(&allocator->shm->blocks, (void *) &p, sizeof(p), (void *) &size, sizeof(size), NULL);
     48#endif
    3749    }
    3850    return p;
    3951}
    4052/* }}} */
    41 static void xc_del_from_blocks(xc_mem_t *mem, void *p) /* {{{ */
    42 {
    43     zend_hash_del(&mem->shm->blocks, (void *) &p, sizeof(p));
    44 }
    45 /* }}} */
    46 
    47 static XC_MEM_MALLOC(xc_malloc_malloc) /* {{{ */
    48 {
    49     return xc_add_to_blocks(mem, malloc(size), size);
    50 }
    51 /* }}} */
    52 static XC_MEM_FREE(xc_malloc_free) /* {{{ return block size freed */
    53 {
    54     xc_del_from_blocks(mem, (void *) p);
     53static void xc_del_from_blocks(xc_allocator_t *allocator, void *p) /* {{{ */
     54{
     55#ifdef TEST
     56    /* TODO: allocator->avail += size; */
     57#else
     58    zend_hash_del(&allocator->shm->blocks, (void *) &p, sizeof(p));
     59#endif
     60}
     61/* }}} */
     62
     63static XC_ALLOCATOR_MALLOC(xc_allocator_malloc_malloc) /* {{{ */
     64{
     65    return xc_add_to_blocks(allocator, malloc(size), size);
     66}
     67/* }}} */
     68static XC_ALLOCATOR_FREE(xc_allocator_malloc_free) /* {{{ return block size freed */
     69{
     70    xc_del_from_blocks(allocator, (void *) p);
    5571    free((void *) p);
    5672    return 0;
    5773}
    5874/* }}} */
    59 static XC_MEM_CALLOC(xc_malloc_calloc) /* {{{ */
    60 {
    61     return xc_add_to_blocks(mem, calloc(memb, size), size);
    62 }
    63 /* }}} */
    64 static XC_MEM_REALLOC(xc_malloc_realloc) /* {{{ */
    65 {
    66     return xc_add_to_blocks(mem, realloc((void *) p, size), size);
    67 }
    68 /* }}} */
    69 static XC_MEM_STRNDUP(xc_malloc_strndup) /* {{{ */
    70 {
    71     char *p = xc_add_to_blocks(mem, malloc(len), len);
    72     if (!p) {
    73         return NULL;
    74     }
    75     return memcpy(p, str, len);
    76 }
    77 /* }}} */
    78 static XC_MEM_STRDUP(xc_malloc_strdup) /* {{{ */
    79 {
    80     return xc_malloc_strndup(mem, str, strlen(str) + 1);
    81 }
    82 /* }}} */
    83 
    84 static XC_MEM_AVAIL(xc_malloc_avail) /* {{{ */
    85 {
    86     return mem->avail;
    87 }
    88 /* }}} */
    89 static XC_MEM_SIZE(xc_malloc_size) /* {{{ */
    90 {
    91     return mem->size;
    92 }
    93 /* }}} */
    94 
    95 static XC_MEM_FREEBLOCK_FIRST(xc_malloc_freeblock_first) /* {{{ */
     75static XC_ALLOCATOR_CALLOC(xc_allocator_malloc_calloc) /* {{{ */
     76{
     77    return xc_add_to_blocks(allocator, calloc(memb, size), size);
     78}
     79/* }}} */
     80static XC_ALLOCATOR_REALLOC(xc_allocator_malloc_realloc) /* {{{ */
     81{
     82    return xc_add_to_blocks(allocator, realloc((void *) p, size), size);
     83}
     84/* }}} */
     85
     86static XC_ALLOCATOR_AVAIL(xc_allocator_malloc_avail) /* {{{ */
     87{
     88    return allocator->avail;
     89}
     90/* }}} */
     91static XC_ALLOCATOR_SIZE(xc_allocator_malloc_size) /* {{{ */
     92{
     93    return allocator->size;
     94}
     95/* }}} */
     96
     97static XC_ALLOCATOR_FREEBLOCK_FIRST(xc_allocator_malloc_freeblock_first) /* {{{ */
    9698{
    9799    return (void *) -1;
    98100}
    99101/* }}} */
    100 XC_MEM_FREEBLOCK_NEXT(xc_malloc_freeblock_next) /* {{{ */
     102static XC_ALLOCATOR_FREEBLOCK_NEXT(xc_allocator_malloc_freeblock_next) /* {{{ */
    101103{
    102104    return NULL;
    103105}
    104106/* }}} */
    105 XC_MEM_BLOCK_SIZE(xc_malloc_block_size) /* {{{ */
    106 {
    107     return 0;
    108 }
    109 /* }}} */
    110 XC_MEM_BLOCK_OFFSET(xc_malloc_block_offset) /* {{{ */
    111 {
    112     return 0;
    113 }
    114 /* }}} */
    115 
    116 static XC_MEM_INIT(xc_mem_malloc_init) /* {{{ */
    117 {
    118 #define MINSIZE (ALIGN(sizeof(xc_mem_t)))
     107static XC_ALLOCATOR_BLOCK_SIZE(xc_allocator_malloc_block_size) /* {{{ */
     108{
     109    return 0;
     110}
     111/* }}} */
     112static XC_ALLOCATOR_BLOCK_OFFSET(xc_allocator_malloc_block_offset) /* {{{ */
     113{
     114    return 0;
     115}
     116/* }}} */
     117
     118static XC_ALLOCATOR_INIT(xc_allocator_malloc_init) /* {{{ */
     119{
     120#define MINSIZE (ALIGN(sizeof(xc_allocator_t)))
    119121    /* requires at least the header and 1 tail block */
    120122    if (size < MINSIZE) {
    121         fprintf(stderr, "xc_mem_malloc_init requires %lu bytes at least\n", (unsigned long) MINSIZE);
     123        fprintf(stderr, "xc_allocator_malloc_init requires %lu bytes at least\n", (unsigned long) MINSIZE);
    122124        return NULL;
    123125    }
    124     mem->shm = shm;
    125     mem->size = size;
    126     mem->avail = size - MINSIZE;
     126    allocator->shm = shm;
     127    allocator->size = size;
     128    allocator->avail = size - MINSIZE;
    127129#undef MINSIZE
    128130
    129     return mem;
    130 }
    131 /* }}} */
    132 static XC_MEM_DESTROY(xc_mem_malloc_destroy) /* {{{ */
     131    return allocator;
     132}
     133/* }}} */
     134static XC_ALLOCATOR_DESTROY(xc_allocator_malloc_destroy) /* {{{ */
    133135{
    134136}
     
    142144static XC_SHM_IS_READWRITE(xc_malloc_is_readwrite) /* {{{ */
    143145{
     146#ifndef TEST
    144147    HashPosition pos;
    145148    size_t *psize;
     
    154157        zend_hash_move_forward_ex(&shm->blocks, &pos);
    155158    }
     159#endif
    156160
    157161    return 0;
     
    176180static XC_SHM_DESTROY(xc_malloc_destroy) /* {{{ */
    177181{
     182#ifndef TEST
    178183    zend_hash_destroy(&shm->blocks);
     184#endif
    179185    free(shm);
    180186    return;
     
    187193    shm->size = size;
    188194
     195#ifndef TEST
    189196    zend_hash_init(&shm->blocks, 64, NULL, NULL, 1);
     197#endif
    190198    return shm;
    191199err:
     
    196204static XC_SHM_MEMINIT(xc_malloc_meminit) /* {{{ */
    197205{
    198     xc_mem_t *mem;
     206    void *mem;
    199207    if (shm->memoffset + size > shm->size) {
     208#ifndef TEST
    200209        zend_error(E_ERROR, "XCache: internal error at %s#%d", __FILE__, __LINE__);
     210#endif
    201211        return NULL;
    202212    }
    203213    shm->memoffset += size;
    204     CHECK(mem = calloc(1, sizeof(xc_mem_t)), "mem OOM");
    205     mem->handlers = shm->handlers->memhandlers;
    206     mem->handlers->init(shm, mem, size);
     214    CHECK(mem = calloc(1, size), "mem OOM");
    207215    return mem;
    208216err:
     
    212220static XC_SHM_MEMDESTROY(xc_malloc_memdestroy) /* {{{ */
    213221{
    214     mem->handlers->destroy(mem);
    215222    free(mem);
    216223}
    217224/* }}} */
    218225
    219 #define xc_malloc_destroy xc_mem_malloc_destroy
    220 #define xc_malloc_init xc_mem_malloc_init
    221 static xc_mem_handlers_t xc_mem_malloc_handlers = XC_MEM_HANDLERS(malloc);
    222 #undef xc_malloc_init
    223 #undef xc_malloc_destroy
     226static xc_allocator_vtable_t xc_allocator_malloc_vtable = XC_ALLOCATOR_VTABLE(allocator_malloc);
    224227static xc_shm_handlers_t xc_shm_malloc_handlers = XC_SHM_HANDLERS(malloc);
     228void xc_allocator_malloc_register() /* {{{ */
     229{
     230    if (xc_allocator_register("malloc", &xc_allocator_malloc_vtable) == 0) {
     231#ifndef TEST
     232        zend_error(E_ERROR, "XCache: failed to register malloc mem_scheme");
     233#endif
     234    }
     235}
     236/* }}} */
     237
     238#ifndef TEST
    225239void xc_shm_malloc_register() /* {{{ */
    226240{
    227     if (xc_mem_scheme_register("malloc", &xc_mem_malloc_handlers) == 0) {
    228         zend_error(E_ERROR, "XCache: failed to register malloc mem_scheme");
    229     }
    230 
    231     CHECK(xc_shm_malloc_handlers.memhandlers = xc_mem_scheme_find("malloc"), "cannot find malloc handlers");
    232241    if (xc_shm_scheme_register("malloc", &xc_shm_malloc_handlers) == 0) {
    233242        zend_error(E_ERROR, "XCache: failed to register malloc shm_scheme");
    234243    }
    235 err:
    236     return;
    237 }
    238 /* }}} */
     244}
     245/* }}} */
     246#endif
  • trunk/xcache/xc_shm.c

    r982 r1135  
    2323void xc_shm_init_modules() /* {{{ */
    2424{
    25     extern void xc_shm_mem_init();
     25    extern void xc_allocator_init();
    2626#ifdef HAVE_XCACHE_TEST
    2727    extern void xc_shm_malloc_register();
     
    3030
    3131    memset(xc_shm_schemes, 0, sizeof(xc_shm_schemes));
    32     xc_shm_mem_init();
     32    xc_allocator_init();
    3333#ifdef HAVE_XCACHE_TEST
    3434    xc_shm_malloc_register();
  • trunk/xcache/xc_shm.h

    r1040 r1135  
    11#ifndef XC_SHM_H
    22#define XC_SHM_H
     3
     4#include <stdlib.h>
     5
    36typedef struct _xc_shm_handlers_t xc_shm_handlers_t;
    47
     
    1316typedef size_t xc_shmsize_t;
    1417
    15 #include "xc_mem.h"
    16 
    1718/* shm */
    1819#define XC_SHM_CAN_READONLY(func) int   func(xc_shm_t *shm)
     
    2526#define XC_SHM_DESTROY(func)      void func(xc_shm_t *shm)
    2627
    27 #define XC_SHM_MEMINIT(func)      xc_mem_t *func(xc_shm_t *shm, xc_memsize_t size)
    28 #define XC_SHM_MEMDESTROY(func)   void func(xc_mem_t *mem)
     28#define XC_SHM_MEMINIT(func)      void *func(xc_shm_t *shm, xc_shmsize_t size)
     29#define XC_SHM_MEMDESTROY(func)   void func(void *mem)
    2930
    3031#define XC_SHM_HANDLERS(name)    { \
    31     NULL                           \
    32     , xc_##name##_can_readonly     \
     32    xc_##name##_can_readonly       \
    3333    , xc_##name##_is_readwrite     \
    3434    , xc_##name##_is_readonly      \
     
    4444
    4545struct _xc_shm_handlers_t {
    46     const xc_mem_handlers_t *memhandlers;
    4746    XC_SHM_CAN_READONLY((*can_readonly));
    4847    XC_SHM_IS_READWRITE((*is_readwrite));
  • trunk/xcache/xc_shm_mmap.c

    r983 r1135  
    295295static XC_SHM_MEMINIT(xc_mmap_meminit) /* {{{ */
    296296{
    297     xc_mem_t *mem;
     297    void *mem;
    298298    if (shm->memoffset + size > shm->size) {
    299299        zend_error(E_ERROR, "XCache: internal error at %s#%d", __FILE__, __LINE__);
    300300        return NULL;
    301301    }
    302     mem = (xc_mem_t *) PTR_ADD(shm->ptr, shm->memoffset);
     302    mem = PTR_ADD(shm->ptr, shm->memoffset);
    303303    shm->memoffset += size;
    304     mem->handlers = shm->handlers->memhandlers;
    305     mem->handlers->init(shm, mem, size);
    306304    return mem;
    307305}
     
    315313void xc_shm_mmap_register() /* {{{ */
    316314{
    317     CHECK(xc_shm_mmap_handlers.memhandlers = xc_mem_scheme_find("mem"), "cannot find mem handlers");
    318315    if (xc_shm_scheme_register("mmap", &xc_shm_mmap_handlers) == 0) {
    319316        zend_error(E_ERROR, "XCache: failed to register mmap shm_scheme");
    320317    }
    321 err:
    322318    return;
    323319}
Note: See TracChangeset for help on using the changeset viewer.