Changeset 1135 for trunk/xcache/xc_allocator.h
- Timestamp:
- 2012-08-09T11:04:02+02:00 (10 months ago)
- Location:
- trunk
- Files:
-
- 1 edited
- 1 moved
-
. (modified) (1 prop)
-
xcache/xc_allocator.h (moved) (moved from trunk/xcache/xc_mem.h) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:ignore
-
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 1 8 #include "xc_shm.h" 2 9 3 typedef struct _xc_ mem_handlers_t xc_mem_handlers_t;10 typedef struct _xc_allocator_vtable_t xc_allocator_vtable_t; 4 11 5 #ifndef XC_MEM_IMPL6 struct _xc_ mem_t {7 const xc_ mem_handlers_t *handlers;8 xc_shm_t *shm;12 #ifndef _xc_allocator_t 13 struct _xc_allocator_t { 14 const xc_allocator_vtable_t *vtable; 15 xc_shm_t *shm; 9 16 }; 10 # define XC_MEM_IMPL _xc_mem_t11 17 #endif 12 18 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; 19 typedef struct _xc_allocator_t xc_allocator_t; 20 typedef struct _xc_allocator_block_t xc_allocator_block_t; 18 21 typedef xc_shmsize_t xc_memsize_t; 19 22 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) 33 34 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) 36 37 37 #define XC_ MEM_HANDLERS(name) { \38 #define XC_ALLOCATOR_VTABLE(name) { \ 38 39 xc_##name##_malloc \ 39 40 , xc_##name##_free \ 40 41 , xc_##name##_calloc \ 41 42 , xc_##name##_realloc \ 42 , xc_##name##_strndup \43 , xc_##name##_strdup \44 43 , xc_##name##_avail \ 45 44 , xc_##name##_size \ … … 53 52 } 54 53 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)); 54 struct _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)); 68 65 69 XC_ MEM_INIT((*init));70 XC_ MEM_DESTROY((*destroy));66 XC_ALLOCATOR_INIT((*init)); 67 XC_ALLOCATOR_DESTROY((*destroy)); 71 68 }; 72 69 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); 70 int xc_allocator_register(const char *name, const xc_allocator_vtable_t *allocator_vtable); 71 const 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.

