source: trunk/mem.h @ 393

Last change on this file since 393 was 393, checked in by moo, 8 years ago

set svn:eol-style

  • Property svn:eol-style set to native
File size: 2.7 KB
Line 
1typedef struct _xc_mem_handlers_t xc_mem_handlers_t;
2
3#ifndef XC_MEM_IMPL
4struct _xc_mem_t {
5    const xc_mem_handlers_t *handlers;
6    xc_shm_t                *shm;
7};
8#   define XC_MEM_IMPL _xc_mem_t
9#endif
10
11#ifndef XC_MEMBLOCK_IMPL
12#   define XC_MEMBLOCK_IMPL _xc_block_t
13#endif
14typedef struct XC_MEM_IMPL xc_mem_t;
15typedef struct XC_MEMBLOCK_IMPL xc_block_t;
16typedef unsigned int xc_memsize_t;
17
18/* shm::mem */
19#define XC_MEM_MALLOC(func)          void *func(xc_mem_t *mem, xc_memsize_t size)
20#define XC_MEM_FREE(func)            xc_memsize_t  func(xc_mem_t *mem, const void *p)
21#define XC_MEM_CALLOC(func)          void *func(xc_mem_t *mem, xc_memsize_t memb, xc_memsize_t size)
22#define XC_MEM_REALLOC(func)         void *func(xc_mem_t *mem, const void *p, xc_memsize_t size)
23#define XC_MEM_STRNDUP(func)         char *func(xc_mem_t *mem, const char *str, xc_memsize_t len)
24#define XC_MEM_STRDUP(func)          char *func(xc_mem_t *mem, const char *str)
25#define XC_MEM_AVAIL(func)           xc_memsize_t      func(xc_mem_t *mem)
26#define XC_MEM_SIZE(func)            xc_memsize_t      func(xc_mem_t *mem)
27#define XC_MEM_FREEBLOCK_FIRST(func) const xc_block_t *func(xc_mem_t *mem)
28#define XC_MEM_FREEBLOCK_NEXT(func)  const xc_block_t *func(const xc_block_t *block)
29#define XC_MEM_BLOCK_SIZE(func)      xc_memsize_t      func(const xc_block_t *block)
30#define XC_MEM_BLOCK_OFFSET(func)    xc_memsize_t      func(const xc_mem_t *mem, const xc_block_t *block)
31
32#define XC_MEM_INIT(func)            xc_mem_t *func(xc_shm_t *shm, xc_mem_t *mem, xc_memsize_t size)
33#define XC_MEM_DESTROY(func)         void func(xc_mem_t *mem)
34
35#define XC_MEM_HANDLERS(name)   {  \
36    xc_##name##_malloc             \
37    , xc_##name##_free             \
38    , xc_##name##_calloc           \
39    , xc_##name##_realloc          \
40    , xc_##name##_strndup          \
41    , xc_##name##_strdup           \
42    , xc_##name##_avail            \
43    , xc_##name##_size             \
44    , xc_##name##_freeblock_first  \
45    , xc_##name##_freeblock_next   \
46    , xc_##name##_block_size       \
47    , xc_##name##_block_offset     \
48\
49    , xc_##name##_init             \
50    , xc_##name##_destroy          \
51}
52
53struct _xc_mem_handlers_t {
54    XC_MEM_MALLOC((*malloc));
55    XC_MEM_FREE((*free));
56    XC_MEM_CALLOC((*calloc));
57    XC_MEM_REALLOC((*realloc));
58    XC_MEM_STRNDUP((*strndup));
59    XC_MEM_STRDUP((*strdup));
60    XC_MEM_AVAIL((*avail));
61    XC_MEM_SIZE((*size));
62    XC_MEM_FREEBLOCK_FIRST((*freeblock_first));
63    XC_MEM_FREEBLOCK_NEXT((*freeblock_next));
64    XC_MEM_BLOCK_SIZE((*block_size));
65    XC_MEM_BLOCK_OFFSET((*block_offset));
66
67    XC_MEM_INIT((*init));
68    XC_MEM_DESTROY((*destroy));
69};
70
71int xc_mem_scheme_register(const char *name, const xc_mem_handlers_t *handlers);
72const xc_mem_handlers_t *xc_mem_scheme_find(const char *name);
Note: See TracBrowser for help on using the repository browser.