source: trunk/mem.h @ 148

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

reconstruct shm/allocator

File size: 2.5 KB
Line 
1typedef struct _xc_mem_t xc_mem_t;
2typedef struct _xc_block_t xc_block_t;
3typedef unsigned int xc_memsize_t;
4
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)
18
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)
21
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 TracBrowser for help on using the repository browser.