| 1 | #include "xc_shm.h" |
|---|
| 2 | |
|---|
| 3 | typedef struct _xc_mem_handlers_t xc_mem_handlers_t; |
|---|
| 4 | |
|---|
| 5 | #ifndef XC_MEM_IMPL |
|---|
| 6 | struct _xc_mem_t { |
|---|
| 7 | const xc_mem_handlers_t *handlers; |
|---|
| 8 | xc_shm_t *shm; |
|---|
| 9 | }; |
|---|
| 10 | # define XC_MEM_IMPL _xc_mem_t |
|---|
| 11 | #endif |
|---|
| 12 | |
|---|
| 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; |
|---|
| 18 | typedef xc_shmsize_t xc_memsize_t; |
|---|
| 19 | |
|---|
| 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(xc_mem_t *mem) |
|---|
| 28 | #define XC_MEM_SIZE(func) xc_memsize_t func(xc_mem_t *mem) |
|---|
| 29 | #define XC_MEM_FREEBLOCK_FIRST(func) const xc_block_t *func(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) |
|---|
| 33 | |
|---|
| 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) |
|---|
| 36 | |
|---|
| 37 | #define XC_MEM_HANDLERS(name) { \ |
|---|
| 38 | xc_##name##_malloc \ |
|---|
| 39 | , xc_##name##_free \ |
|---|
| 40 | , xc_##name##_calloc \ |
|---|
| 41 | , xc_##name##_realloc \ |
|---|
| 42 | , xc_##name##_strndup \ |
|---|
| 43 | , xc_##name##_strdup \ |
|---|
| 44 | , xc_##name##_avail \ |
|---|
| 45 | , xc_##name##_size \ |
|---|
| 46 | , xc_##name##_freeblock_first \ |
|---|
| 47 | , xc_##name##_freeblock_next \ |
|---|
| 48 | , xc_##name##_block_size \ |
|---|
| 49 | , xc_##name##_block_offset \ |
|---|
| 50 | \ |
|---|
| 51 | , xc_##name##_init \ |
|---|
| 52 | , xc_##name##_destroy \ |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 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)); |
|---|
| 68 | |
|---|
| 69 | XC_MEM_INIT((*init)); |
|---|
| 70 | XC_MEM_DESTROY((*destroy)); |
|---|
| 71 | }; |
|---|
| 72 | |
|---|
| 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); |
|---|