Changeset 148


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

reconstruct shm/allocator

Location:
trunk
Files:
2 added
11 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/Makefile.frag

    r75 r148  
    3232disassembler.lo: $(XCACHE_PROC_H) $(srcdir)/processor.c
    3333
    34 $(builddir)/xcache.lo: $(XCACHE_PROC_H) $(srcdir)/myshm.h $(srcdir)/stack.h $(srcdir)/xcache_globals.h $(srcdir)/xcache.c $(srcdir)/foreachcoresig.h
    35 xcache.lo: $(XCACHE_PROC_H) $(srcdir)/myshm.h $(srcdir)/stack.h $(srcdir)/xcache_globals.h $(srcdir)/xcache.c $(srcdir)/foreachcoresig.h
     34$(builddir)/xcache.lo: $(XCACHE_PROC_H) $(srcdir)/xc_shm.h $(srcdir)/stack.h $(srcdir)/xcache_globals.h $(srcdir)/xcache.c $(srcdir)/foreachcoresig.h
     35xcache.lo: $(XCACHE_PROC_H) $(srcdir)/xc_shm.h $(srcdir)/stack.h $(srcdir)/xcache_globals.h $(srcdir)/xcache.c $(srcdir)/foreachcoresig.h
    3636
    3737xcachesvnclean: clean
  • trunk/config.m4

    r95 r148  
    2828                  mmap.c \
    2929                  mem.c \
     30                  xc_malloc.c \
     31                  xc_shm.c \
    3032                  const_string.c \
    3133                  opcode_spec.c \
  • trunk/config.w32

    r95 r148  
    1616                          mmap.c \
    1717                          mem.c \
     18                          xc_malloc.c \
     19                          xc_shm.c \
    1820                          const_string.c \
    1921                          opcode_spec.c \
  • trunk/mem.c

    r112 r148  
    99#include <stdlib.h>
    1010#include <string.h>
    11 #include "mem.h"
     11#define XC_SHM_IMPL
     12#define XC_MEM_IMPL
     13#include "xc_shm.h"
    1214#include "align.h"
    1315
     
    3739
    3840struct _xc_mem_t {
     41    const xc_mem_handlers_t *handlers;
     42    xc_shm_t                *shm;
    3943    xc_memsize_t size;
    4044    xc_memsize_t avail;       /* total free */
     
    7579
    7680
    77 void *xc_mem_malloc(xc_mem_t *mem, xc_memsize_t size) /* {{{ */
     81static XC_MEM_MALLOC(xc_mem_malloc) /* {{{ */
    7882{
    7983    xc_block_t *prev, *cur;
     
    183187}
    184188/* }}} */
    185 int xc_mem_free(xc_mem_t *mem, const void *p) /* {{{ return block size freed */
     189static XC_MEM_FREE(xc_mem_free) /* {{{ return block size freed */
    186190{
    187191    xc_block_t *cur, *b;
     
    237241}
    238242/* }}} */
    239 void *xc_mem_calloc(xc_mem_t *mem, xc_memsize_t memb, xc_memsize_t size) /* {{{ */
     243static XC_MEM_CALLOC(xc_mem_calloc) /* {{{ */
    240244{
    241245    xc_memsize_t realsize = memb * size;
     
    248252}
    249253/* }}} */
    250 void *xc_mem_realloc(xc_mem_t *mem, const void *p, xc_memsize_t size) /* {{{ */
     254static XC_MEM_REALLOC(xc_mem_realloc) /* {{{ */
    251255{
    252256    void *newp = xc_mem_malloc(mem, size);
     
    258262}
    259263/* }}} */
    260 char *xc_mem_strndup(xc_mem_t *mem, const char *str, xc_memsize_t len) /* {{{ */
     264static XC_MEM_STRNDUP(xc_mem_strndup) /* {{{ */
    261265{
    262266    void *p = xc_mem_malloc(mem, len + 1);
     
    267271}
    268272/* }}} */
    269 char *xc_mem_strdup(xc_mem_t *mem, const char *str) /* {{{ */
     273static XC_MEM_STRDUP(xc_mem_strdup) /* {{{ */
    270274{
    271275    return xc_mem_strndup(mem, str, strlen(str));
     
    273277/* }}} */
    274278
    275 xc_memsize_t xc_mem_avail(xc_mem_t *mem) /* {{{ */
     279static XC_MEM_AVAIL(xc_mem_avail) /* {{{ */
    276280{
    277281    return mem->avail;
    278282}
    279283/* }}} */
    280 xc_memsize_t xc_mem_size(xc_mem_t *mem) /* {{{ */
     284static XC_MEM_SIZE(xc_mem_size) /* {{{ */
    281285{
    282286    return mem->size;
     
    284288/* }}} */
    285289
    286 const xc_block_t *xc_mem_freeblock_first(xc_mem_t *mem) /* {{{ */
     290static XC_MEM_FREEBLOCK_FIRST(xc_mem_freeblock_first) /* {{{ */
    287291{
    288292    return mem->headblock->next;
    289293}
    290294/* }}} */
    291 const xc_block_t *xc_mem_freeblock_next(const xc_block_t *block) /* {{{ */
     295XC_MEM_FREEBLOCK_NEXT(xc_mem_freeblock_next) /* {{{ */
    292296{
    293297    return block->next;
    294298}
    295299/* }}} */
    296 xc_memsize_t xc_mem_block_size(const xc_block_t *block) /* {{{ */
     300XC_MEM_BLOCK_SIZE(xc_mem_block_size) /* {{{ */
    297301{
    298302    return block->size;
    299303}
    300304/* }}} */
    301 xc_memsize_t xc_mem_block_offset(const xc_mem_t *mem, const xc_block_t *block) /* {{{ */
     305XC_MEM_BLOCK_OFFSET(xc_mem_block_offset) /* {{{ */
    302306{
    303307    return ((char *) block) - ((char *) mem);
     
    305309/* }}} */
    306310
    307 xc_mem_t *xc_mem_init(void *ptr, xc_memsize_t size) /* {{{ */
    308 {
    309     xc_mem_t   *mem;
     311static XC_MEM_INIT(xc_mem_init) /* {{{ */
     312{
    310313    xc_block_t *b;
    311 
    312314#define MINSIZE (ALIGN(sizeof(xc_mem_t)) + sizeof(xc_block_t))
    313315    /* requires at least the header and 1 tail block */
     
    316318        return NULL;
    317319    }
    318     mem = (xc_mem_t *) ptr;
     320    mem->shm = shm;
    319321    mem->size = size;
    320322    mem->avail = size - MINSIZE;
     
    332334}
    333335/* }}} */
    334 void xc_mem_destroy(xc_mem_t *mem) /* {{{ */
     336static XC_MEM_DESTROY(xc_mem_destroy) /* {{{ */
    335337{
    336338}
     
    381383/* }}} */
    382384#endif
     385
     386typedef struct {
     387    const char              *name;
     388    const xc_mem_handlers_t *handlers;
     389} xc_mem_scheme_t;
     390static xc_mem_scheme_t xc_mem_schemes[10];
     391
     392int xc_mem_scheme_register(const char *name, const xc_mem_handlers_t *handlers) /* {{{ */
     393{
     394    int i;
     395    for (i = 0; i < 10; i ++) {
     396        if (!xc_mem_schemes[i].name) {
     397            xc_mem_schemes[i].name = name;
     398            xc_mem_schemes[i].handlers = handlers;
     399            return 1;
     400        }
     401    }
     402    return 0;
     403}
     404/* }}} */
     405const xc_mem_handlers_t *xc_mem_scheme_find(const char *name) /* {{{ */
     406{
     407    int i;
     408    for (i = 0; i < 10 && xc_mem_schemes[i].name; i ++) {
     409        if (strcmp(xc_mem_schemes[i].name, name) == 0) {
     410            return xc_mem_schemes[i].handlers;
     411        }
     412    }
     413    return NULL;
     414}
     415/* }}} */
     416
     417static xc_mem_handlers_t xc_mem_mem_handlers = XC_MEM_HANDLERS(mem);
     418void xc_shm_mem_init() /* {{{ */
     419{
     420    memset(xc_mem_schemes, 0, sizeof(xc_mem_schemes));
     421
     422    if (xc_mem_scheme_register("mem", &xc_mem_mem_handlers) == 0) {
     423        zend_error(E_ERROR, "XCache: failed to register mem mem_scheme");
     424    }
     425}
     426/* }}} */
  • trunk/mem.h

    r1 r148  
    33typedef unsigned int xc_memsize_t;
    44
    5 void *xc_mem_malloc(xc_mem_t *mem, xc_memsize_t size);
    6 int xc_mem_free(xc_mem_t *mem, const void *p);
    7 void *xc_mem_calloc(xc_mem_t *mem, xc_memsize_t memb, xc_memsize_t size);
    8 void *xc_mem_realloc(xc_mem_t *mem, const void *p, xc_memsize_t size);
    9 char *xc_mem_strndup(xc_mem_t *mem, const char *str, xc_memsize_t len);
    10 char *xc_mem_strdup(xc_mem_t *mem, const char *str);
    11 const xc_block_t *xc_mem_freeblock_first(xc_mem_t *mem);
    12 const xc_block_t *xc_mem_freeblock_next(const xc_block_t *block);
    13 xc_memsize_t xc_mem_block_size(const xc_block_t *block);
    14 xc_memsize_t xc_mem_block_offset(const xc_mem_t *mem, const xc_block_t *block);
     5/* shm::mem */
     6#define XC_MEM_MALLOC(func)          void *func(xc_mem_t *mem, xc_memsize_t size)
     7#define XC_MEM_FREE(func)            xc_memsize_t  func(xc_mem_t *mem, const void *p)
     8#define XC_MEM_CALLOC(func)          void *func(xc_mem_t *mem, xc_memsize_t memb, xc_memsize_t size)
     9#define XC_MEM_REALLOC(func)         void *func(xc_mem_t *mem, const void *p, xc_memsize_t size)
     10#define XC_MEM_STRNDUP(func)         char *func(xc_mem_t *mem, const char *str, xc_memsize_t len)
     11#define XC_MEM_STRDUP(func)          char *func(xc_mem_t *mem, const char *str)
     12#define XC_MEM_AVAIL(func)           xc_memsize_t      func(xc_mem_t *mem)
     13#define XC_MEM_SIZE(func)            xc_memsize_t      func(xc_mem_t *mem)
     14#define XC_MEM_FREEBLOCK_FIRST(func) const xc_block_t *func(xc_mem_t *mem)
     15#define XC_MEM_FREEBLOCK_NEXT(func)  const xc_block_t *func(const xc_block_t *block)
     16#define XC_MEM_BLOCK_SIZE(func)      xc_memsize_t      func(const xc_block_t *block)
     17#define XC_MEM_BLOCK_OFFSET(func)    xc_memsize_t      func(const xc_mem_t *mem, const xc_block_t *block)
    1518
    16 xc_memsize_t xc_mem_avail(xc_mem_t *mem);
    17 xc_memsize_t xc_mem_size(xc_mem_t *mem);
     19#define XC_MEM_INIT(func)            xc_mem_t *func(xc_shm_t *shm, xc_mem_t *mem, xc_memsize_t size)
     20#define XC_MEM_DESTROY(func)         void func(xc_mem_t *mem)
    1821
    19 xc_mem_t *xc_mem_init(void *ptr, xc_memsize_t size);
    20 void xc_mem_destroy(xc_mem_t *mem);
     22#define XC_MEM_HANDLERS(name)   {  \
     23    xc_##name##_malloc             \
     24    , xc_##name##_free             \
     25    , xc_##name##_calloc           \
     26    , xc_##name##_realloc          \
     27    , xc_##name##_strndup          \
     28    , xc_##name##_strdup           \
     29    , xc_##name##_avail            \
     30    , xc_##name##_size             \
     31    , xc_##name##_freeblock_first  \
     32    , xc_##name##_freeblock_next   \
     33    , xc_##name##_block_size       \
     34    , xc_##name##_block_offset     \
     35\
     36    , xc_##name##_init             \
     37    , xc_##name##_destroy          \
     38}
     39
     40typedef struct {
     41    XC_MEM_MALLOC((*malloc));
     42    XC_MEM_FREE((*free));
     43    XC_MEM_CALLOC((*calloc));
     44    XC_MEM_REALLOC((*realloc));
     45    XC_MEM_STRNDUP((*strndup));
     46    XC_MEM_STRDUP((*strdup));
     47    XC_MEM_AVAIL((*avail));
     48    XC_MEM_SIZE((*size));
     49    XC_MEM_FREEBLOCK_FIRST((*freeblock_first));
     50    XC_MEM_FREEBLOCK_NEXT((*freeblock_next));
     51    XC_MEM_BLOCK_SIZE((*block_size));
     52    XC_MEM_BLOCK_OFFSET((*block_offset));
     53
     54    XC_MEM_INIT((*init));
     55    XC_MEM_DESTROY((*destroy));
     56} xc_mem_handlers_t;
     57
     58#ifndef XC_MEM_IMPL
     59struct _xc_mem_t {
     60    const xc_mem_handlers_t *handlers;
     61    xc_shm_t                *shm;
     62};
     63#endif
     64
     65int xc_mem_scheme_register(const char *name, const xc_mem_handlers_t *handlers);
     66const xc_mem_handlers_t *xc_mem_scheme_find(const char *name);
  • trunk/mmap.c

    r119 r148  
    3232
    3333#include "php.h"
    34 #include "myshm.h"
     34#define XC_SHM_IMPL
     35#include "xc_shm.h"
    3536
    3637#ifndef max
     
    4041// {{{ xc_shm_t
    4142struct _xc_shm_t {
     43    xc_shm_handlers_t *handlers;
    4244    void *ptr;
    4345    void *ptr_ro;
     
    4648    char *name;
    4749    int newfile;
     50    xc_shmsize_t memoffset;
    4851#ifdef ZEND_WIN32
    4952    HANDLE hmap;
     
    6467#define PTR_SUB(ptr, v) (((char *) (ptr)) - (v))
    6568
    66 int xc_shm_can_readonly(xc_shm_t *shm) /* {{{ */
     69static XC_SHM_CAN_READONLY(xc_mmap_can_readonly) /* {{{ */
    6770{
    6871    return shm->ptr_ro != NULL;
    6972}
    7073/* }}} */
    71 int xc_shm_is_readwrite(xc_shm_t *shm, const void *p) /* {{{ */
     74static XC_SHM_IS_READWRITE(xc_mmap_is_readwrite) /* {{{ */
    7275{
    7376    return p >= shm->ptr && (char *)p < (char *)shm->ptr + shm->size;
    7477}
    7578/* }}} */
    76 int xc_shm_is_readonly(xc_shm_t *shm, const void *p) /* {{{ */
    77 {
    78     return xc_shm_can_readonly(shm) && p >= shm->ptr_ro && (char *)p < (char *)shm->ptr_ro + shm->size;
    79 }
    80 /* }}} */
    81 void *xc_shm_to_readwrite(xc_shm_t *shm, void *p) /* {{{ */
     79static XC_SHM_IS_READONLY(xc_mmap_is_readonly) /* {{{ */
     80{
     81    return xc_mmap_can_readonly(shm) && p >= shm->ptr_ro && (char *)p < (char *)shm->ptr_ro + shm->size;
     82}
     83/* }}} */
     84static XC_SHM_TO_READWRITE(xc_mmap_to_readwrite) /* {{{ */
    8285{
    8386    if (shm->diff) {
    84         assert(xc_shm_is_readonly(p));
     87        assert(xc_mmap_is_readonly(p));
    8588        p = PTR_SUB(p, shm->diff);
    8689    }
    87     assert(xc_shm_is_readwrite(p));
     90    assert(xc_mmap_is_readwrite(p));
    8891    return p;
    8992}
    9093/* }}} */
    91 void *xc_shm_to_readonly(xc_shm_t *shm, void *p) /* {{{ */
     94static XC_SHM_TO_READONLY(xc_mmap_to_readonly) /* {{{ */
    9295{
    9396    assert(xc_shm_is_readwrite(p));
    9497    if (shm->diff) {
    9598        p = PTR_ADD(p, shm->diff);
    96         assert(xc_shm_is_readonly(p));
     99        assert(xc_mmap_is_readonly(p));
    97100    }
    98101    return p;
     
    100103/* }}} */
    101104
    102 void xc_shm_destroy(xc_shm_t *shm) /* {{{ */
     105static XC_SHM_DESTROY(xc_mmap_destroy) /* {{{ */
    103106{
    104107    if (shm->ptr_ro) {
     
    141144}
    142145/* }}} */
    143 xc_shm_t *xc_shm_init(const char *path, xc_shmsize_t size, zend_bool readonly_protection) /* {{{ */
     146static XC_SHM_INIT(xc_mmap_init) /* {{{ */
    144147{
    145148#ifdef ZEND_WIN32
     
    154157    char tmpname[sizeof(TMP_PATH) - 1 + 100];
    155158    const char *errstr = NULL;
     159    const char *path = (const char *) arg1;
    156160
    157161    CHECK(shm = calloc(1, sizeof(xc_shm_t)), "shm OOM");
     
    273277    }
    274278    if (shm) {
    275         xc_shm_destroy(shm);
     279        xc_mmap_destroy(shm);
    276280    }
    277281    if (errstr) {
     
    283287/* }}} */
    284288
    285 void *xc_shm_ptr(xc_shm_t *shm) /* {{{ */
    286 {
    287     return shm->ptr;
    288 }
    289 /* }}} */
     289static XC_SHM_MEMINIT(xc_mmap_meminit) /* {{{ */
     290{
     291    xc_mem_t *mem;
     292    if (shm->memoffset + size > shm->size) {
     293        zend_error(E_ERROR, "XCache: internal error at %s#%d", __FILE__, __LINE__);
     294        return NULL;
     295    }
     296    mem = (xc_mem_t *) PTR_ADD(shm->ptr, shm->memoffset);
     297    shm->memoffset += size;
     298    mem->handlers = shm->handlers->memhandlers;
     299    mem->handlers->init(shm, mem, size);
     300    return mem;
     301}
     302/* }}} */
     303static XC_SHM_MEMDESTROY(xc_mmap_memdestroy) /* {{{ */
     304{
     305}
     306/* }}} */
     307
     308static xc_shm_handlers_t xc_shm_mmap_handlers = XC_SHM_HANDLERS(mmap);
     309void xc_shm_mmap_register() /* {{{ */
     310{
     311    CHECK(xc_shm_mmap_handlers.memhandlers = xc_mem_scheme_find("mem"), "cannot find mem handlers");
     312    if (xc_shm_scheme_register("mmap", &xc_shm_mmap_handlers) == 0) {
     313        zend_error(E_ERROR, "XCache: failed to register mmap shm_scheme");
     314    }
     315err:
     316    return;
     317}
     318/* }}} */
  • trunk/processor/head.m4

    r103 r148  
    288288
    289289        /* mem :) */
    290         processor.p = (char *)xc_mem_malloc(src->cache->mem, processor.size);
     290        processor.p = (char *) src->cache->mem->handlers->malloc(src->cache->mem, processor.size);
    291291        if (processor.p == NULL) {
    292292            dst = NULL;
  • trunk/processor/main.m4

    r90 r148  
    118118define(`FIXPOINTER', `FIXPOINTER_EX(`$1', `dst->$2')')
    119119define(`FIXPOINTER_EX', `IFSTORE(`
    120     $2 = ($1 *) xc_shm_to_readonly(processor->xce_src->cache->shm, (char *)$2);
     120    $2 = ($1 *) processor->xce_src->cache->shm->handlers->to_readonly(processor->xce_src->cache->shm, (char *)$2);
    121121')')
    122122define(`UNFIXPOINTER', `UNFIXPOINTER_EX(`$1', `dst->$2')')
    123123define(`UNFIXPOINTER_EX', `IFSTORE(`
    124     $2 = ($1 *) xc_shm_to_readwrite(processor->xce_src->cache->shm, (char *)$2);
     124    $2 = ($1 *) processor->xce_src->cache->shm->handlers->to_readwrite(processor->xce_src->cache->shm, (char *)$2);
    125125')')
    126126dnl }}}
  • trunk/utils.c

    r131 r148  
    404404    int i;
    405405    Bucket *b;
    406     zend_llist_position lpos;
    407     zend_file_handle *handle;
    408406
    409407#ifdef HAVE_XCACHE_CONSTANT
  • trunk/xc_shm.h

    r137 r148  
    22typedef size_t xc_shmsize_t;
    33
    4 int xc_shm_can_readonly(xc_shm_t *shm);
    5 int xc_shm_is_readwrite(xc_shm_t *shm, const void *p);
    6 int xc_shm_is_readonly(xc_shm_t *shm, const void *p);
    7 void *xc_shm_to_readwrite(xc_shm_t *shm, void *p);
    8 void *xc_shm_to_readonly(xc_shm_t *shm, void *p);
     4#include "mem.h"
    95
    10 void *xc_shm_ptr(xc_shm_t *shm);
     6/* shm */
     7#define XC_SHM_CAN_READONLY(func) int   func(xc_shm_t *shm)
     8#define XC_SHM_IS_READWRITE(func) int   func(xc_shm_t *shm, const void *p)
     9#define XC_SHM_IS_READONLY(func)  int   func(xc_shm_t *shm, const void *p)
     10#define XC_SHM_TO_READWRITE(func) void *func(xc_shm_t *shm, void *p)
     11#define XC_SHM_TO_READONLY(func)  void *func(xc_shm_t *shm, void *p)
    1112
    12 xc_shm_t *xc_shm_init(const char *path, xc_shmsize_t size, zend_bool readonly_protection);
     13#define XC_SHM_INIT(func)         xc_shm_t *func(xc_shmsize_t size, int readonly_protection, const void *arg1, const void *arg2)
     14#define XC_SHM_DESTROY(func)      void func(xc_shm_t *shm)
     15
     16#define XC_SHM_MEMINIT(func)      xc_mem_t *func(xc_shm_t *shm, xc_memsize_t size)
     17#define XC_SHM_MEMDESTROY(func)   void func(xc_mem_t *mem)
     18
     19#define XC_SHM_HANDLERS(name)    { \
     20    NULL                           \
     21    , xc_##name##_can_readonly     \
     22    , xc_##name##_is_readwrite     \
     23    , xc_##name##_is_readonly      \
     24    , xc_##name##_to_readwrite     \
     25    , xc_##name##_to_readonly      \
     26\
     27    , xc_##name##_init             \
     28    , xc_##name##_destroy          \
     29\
     30    , xc_##name##_meminit          \
     31    , xc_##name##_memdestroy       \
     32}
     33
     34typedef struct {
     35    const xc_mem_handlers_t *memhandlers;
     36    XC_SHM_CAN_READONLY((*can_readonly));
     37    XC_SHM_IS_READWRITE((*is_readwrite));
     38    XC_SHM_IS_READONLY((*is_readonly));
     39    XC_SHM_TO_READWRITE((*to_readwrite));
     40    XC_SHM_TO_READONLY((*to_readonly));
     41    XC_SHM_INIT((*init));
     42    XC_SHM_DESTROY((*destroy));
     43
     44    XC_SHM_MEMINIT((*meminit));
     45    XC_SHM_MEMDESTROY((*memdestroy));
     46} xc_shm_handlers_t;
     47
     48
     49#ifndef XC_SHM_IMPL
     50struct _xc_shm_t {
     51    const xc_shm_handlers_t *handlers;
     52};
     53#endif
     54
     55void xc_shm_init_modules();
     56int xc_shm_scheme_register(const char *name, const xc_shm_handlers_t *handlers);
     57const xc_shm_handlers_t *xc_shm_scheme_find(const char *name);
     58
     59xc_shm_t *xc_shm_init(const char *type, xc_shmsize_t size, int readonly_protection, const void *arg1, const void *arg2);
    1360void xc_shm_destroy(xc_shm_t *shm);
  • 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
  • trunk/xcache.h

    r114 r148  
    1616#include <config.h>
    1717#endif
    18 #include "myshm.h"
    19 #include "mem.h"
     18#include "xc_shm.h"
    2019#include "lock.h"
    2120
Note: See TracChangeset for help on using the changeset viewer.