Changeset 148 for trunk/mem.h


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

reconstruct shm/allocator

File:
1 edited

Legend:

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