Ignore:
Timestamp:
2013-11-12T10:46:04+01:00 (5 months ago)
Author:
moo
Message:

clean up shm handlers

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/xcache/xc_malloc.c

    r1392 r1468  
    1 #define XC_SHM_IMPL _xc_malloc_shm_t 
     1typedef struct xc_malloc_shm_t xc_shm_t; 
     2#define XC_SHM_T_DEFINED 
    23#define _xc_allocator_t _xc_allocator_malloc_t 
     4 
    35#include <stdlib.h> 
    46#include <stdio.h> 
     
    1921}; 
    2022 
    21 /* {{{ _xc_malloc_shm_t */ 
    22 struct _xc_malloc_shm_t { 
    23     xc_shm_handlers_t *handlers; 
    24     xc_shmsize_t       size; 
    25     xc_shmsize_t       memoffset; 
     23/* {{{ xc_malloc_shm_t */ 
     24struct xc_malloc_shm_t { 
     25    xc_shm_vtable_t *vtable; 
     26    xc_shmsize_t     size; 
     27    xc_shmsize_t     memoffset; 
    2628#ifndef TEST 
    2729    HashTable blocks; 
     
    139141/* }}} */ 
    140142 
    141 static XC_SHM_CAN_READONLY(xc_malloc_can_readonly) /* {{{ */ 
    142 { 
    143     return 0; 
    144 } 
    145 /* }}} */ 
     143static XC_SHM_DESTROY(xc_malloc_destroy) /* {{{ */ 
     144{ 
     145#ifndef TEST 
     146    zend_hash_destroy(&shm->blocks); 
     147#endif 
     148    free(shm); 
     149    return; 
     150} 
     151/* }}} */ 
     152static XC_SHM_INIT(xc_malloc_init) /* {{{ */ 
     153{ 
     154    xc_shm_t *shm; 
     155    CHECK(shm = calloc(1, sizeof(xc_shm_t)), "shm OOM"); 
     156    shm->size = size; 
     157 
     158#ifndef TEST 
     159    zend_hash_init(&shm->blocks, 64, NULL, NULL, 1); 
     160#endif 
     161    return shm; 
     162err: 
     163    return NULL; 
     164} 
     165/* }}} */ 
     166 
    146167static XC_SHM_IS_READWRITE(xc_malloc_is_readwrite) /* {{{ */ 
    147168{ 
     
    150171    size_t *psize; 
    151172    char **ptr; 
    152  
    153     zend_hash_internal_pointer_reset_ex(&shm->blocks, &pos); 
    154     while (zend_hash_get_current_data_ex(&shm->blocks, (void **) &psize, &pos) == SUCCESS) { 
    155         zend_hash_get_current_key_ex(&shm->blocks, (void *) &ptr, NULL, NULL, 0, &pos); 
     173    HashTable *blocks = &((xc_shm_t *) shm)->blocks; 
     174 
     175    zend_hash_internal_pointer_reset_ex(blocks, &pos); 
     176    while (zend_hash_get_current_data_ex(blocks, (void **) &psize, &pos) == SUCCESS) { 
     177        zend_hash_get_current_key_ex(blocks, (void *) &ptr, NULL, NULL, 0, &pos); 
    156178        if ((char *) p >= *ptr && (char *) p < *ptr + *psize) { 
    157179            return 1; 
    158180        } 
    159         zend_hash_move_forward_ex(&shm->blocks, &pos); 
     181        zend_hash_move_forward_ex(blocks, &pos); 
    160182    } 
    161183#endif 
     
    167189{ 
    168190    return 0; 
    169 } 
    170 /* }}} */ 
    171 static XC_SHM_TO_READWRITE(xc_malloc_to_readwrite) /* {{{ */ 
    172 { 
    173     return p; 
    174 } 
    175 /* }}} */ 
    176 static XC_SHM_TO_READONLY(xc_malloc_to_readonly) /* {{{ */ 
    177 { 
    178     return p; 
    179 } 
    180 /* }}} */ 
    181  
    182 static XC_SHM_DESTROY(xc_malloc_destroy) /* {{{ */ 
    183 { 
    184 #ifndef TEST 
    185     zend_hash_destroy(&shm->blocks); 
    186 #endif 
    187     free(shm); 
    188     return; 
    189 } 
    190 /* }}} */ 
    191 static XC_SHM_INIT(xc_malloc_init) /* {{{ */ 
    192 { 
    193     xc_shm_t *shm; 
    194     CHECK(shm = calloc(1, sizeof(xc_shm_t)), "shm OOM"); 
    195     shm->size = size; 
    196  
    197 #ifndef TEST 
    198     zend_hash_init(&shm->blocks, 64, NULL, NULL, 1); 
    199 #endif 
    200     return shm; 
    201 err: 
    202     return NULL; 
    203191} 
    204192/* }}} */ 
     
    228216static xc_allocator_vtable_t xc_allocator_malloc_vtable = XC_ALLOCATOR_VTABLE(allocator_malloc); 
    229217#ifndef TEST 
    230 static xc_shm_handlers_t xc_shm_malloc_handlers = XC_SHM_HANDLERS(malloc); 
     218static xc_shm_vtable_t xc_shm_malloc_vtable = XC_SHM_VTABLE(malloc); 
    231219#endif 
    232220void xc_allocator_malloc_register() /* {{{ */ 
     
    243231void xc_shm_malloc_register() /* {{{ */ 
    244232{ 
    245     if (xc_shm_scheme_register("malloc", &xc_shm_malloc_handlers) == 0) { 
     233    if (xc_shm_scheme_register("malloc", &xc_shm_malloc_vtable) == 0) { 
    246234        zend_error(E_ERROR, "XCache: failed to register malloc shm_scheme"); 
    247235    } 
Note: See TracChangeset for help on using the changeset viewer.