Changeset 1135 in svn for trunk/xcache/xc_allocator.h


Ignore:
Timestamp:
2012-08-09T09:04:02Z (3 years ago)
Author:
Xuefer
Message:

refactor: s/mem/allocator/

Location:
trunk
Files:
1 edited
1 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/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 */
Note: See TracChangeset for help on using the changeset viewer.