Changeset 148 for trunk/mmap.c


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

reconstruct shm/allocator

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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/* }}} */
Note: See TracChangeset for help on using the changeset viewer.