Changeset 2123 for pjproject/trunk
- Timestamp:
- Jul 12, 2008 9:31:34 AM (16 years ago)
- Location:
- pjproject/trunk/pjlib
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib/include/pj/pool_alt.h
r2039 r2123 23 23 24 24 25 typedef struct pj_pool_t pj_pool_t;26 27 28 25 /** 29 26 * The type for function to receive callback from the pool when it is unable … … 33 30 */ 34 31 typedef void pj_pool_callback(pj_pool_t *pool, pj_size_t size); 32 33 struct pj_pool_mem 34 { 35 struct pj_pool_mem *next; 36 37 /* data follows immediately */ 38 }; 39 40 41 typedef struct pj_pool_t 42 { 43 struct pj_pool_mem *first_mem; 44 pj_pool_factory *factory; 45 char obj_name[32]; 46 pj_size_t used_size; 47 pj_pool_callback *cb; 48 } pj_pool_t; 49 50 35 51 36 52 /** … … 106 122 107 123 124 #define PJ_POOL_ZALLOC_T(pool,type) \ 125 ((type*)pj_pool_zalloc(pool, sizeof(type))) 126 #define PJ_POOL_ALLOC_T(pool,type) \ 127 ((type*)pj_pool_alloc(pool, sizeof(type))) 128 #ifndef PJ_POOL_ALIGNMENT 129 # define PJ_POOL_ALIGNMENT 4 130 #endif 131 132 /** 133 * This structure declares pool factory interface. 134 */ 135 typedef struct pj_pool_factory_policy 136 { 137 /** 138 * Allocate memory block (for use by pool). This function is called 139 * by memory pool to allocate memory block. 140 * 141 * @param factory Pool factory. 142 * @param size The size of memory block to allocate. 143 * 144 * @return Memory block. 145 */ 146 void* (*block_alloc)(pj_pool_factory *factory, pj_size_t size); 147 148 /** 149 * Free memory block. 150 * 151 * @param factory Pool factory. 152 * @param mem Memory block previously allocated by block_alloc(). 153 * @param size The size of memory block. 154 */ 155 void (*block_free)(pj_pool_factory *factory, void *mem, pj_size_t size); 156 157 /** 158 * Default callback to be called when memory allocation fails. 159 */ 160 pj_pool_callback *callback; 161 162 /** 163 * Option flags. 164 */ 165 unsigned flags; 166 167 } pj_pool_factory_policy; 168 108 169 typedef struct pj_pool_factory 109 170 { 171 pj_pool_factory_policy policy; 110 172 int dummy; 111 173 } pj_pool_factory; … … 121 183 #define pj_pool_factory_dump(pf, detail) 122 184 123 124 185 #endif /* __PJ_POOL_ALT_H__ */ 125 186 -
pjproject/trunk/pjlib/src/pj/pool_buf.c
r2039 r2123 81 81 pj_size_t size) 82 82 { 83 #if PJ_HAS_POOL_ALT_API == 0 83 84 struct creation_param param; 84 85 long align_diff; … … 106 107 return pj_pool_create_int(&stack_based_factory, name, size, 0, 107 108 pj_pool_factory_default_policy.callback); 109 #else 110 PJ_UNUSED_ARG(buf); 111 return pj_pool_create(NULL, name, size, size, NULL); 112 #endif 108 113 } 109 114 -
pjproject/trunk/pjlib/src/pj/pool_dbg.c
r2039 r2123 20 20 #include <pj/string.h> 21 21 22 #if PJ_ POOL_DEBUG22 #if PJ_HAS_POOL_ALT_API 23 23 24 24 #if PJ_HAS_MALLOC_H … … 42 42 43 43 44 struct pj_pool_mem45 {46 struct pj_pool_mem *next;47 48 /* data follows immediately */49 };50 51 52 struct pj_pool_t53 {54 struct pj_pool_mem *first_mem;55 pj_size_t used_size;56 pj_pool_callback *cb;57 };58 59 44 60 45 int PJ_NO_MEMORY_EXCEPTION; 61 46 47 48 PJ_DEF(int) pj_NO_MEMORY_EXCEPTION() 49 { 50 return PJ_NO_MEMORY_EXCEPTION; 51 } 62 52 63 53 /* Create pool */ … … 74 64 PJ_UNUSED_ARG(line); 75 65 PJ_UNUSED_ARG(factory); 76 PJ_UNUSED_ARG(name);77 66 PJ_UNUSED_ARG(initial_size); 78 67 PJ_UNUSED_ARG(increment_size); … … 82 71 return NULL; 83 72 73 if (name) { 74 pj_ansi_strncpy(pool->obj_name, name, sizeof(pool->obj_name)); 75 pool->obj_name[sizeof(pool->obj_name)-1] = '\0'; 76 } else { 77 strcpy(pool->obj_name, "altpool"); 78 } 79 80 pool->factory = NULL; 84 81 pool->first_mem = NULL; 85 82 pool->used_size = 0; … … 185 182 pj_pool_t *pool, pj_size_t sz) 186 183 { 187 return pj_pool_calloc_imp(file, line, pool, 1, sz); 184 return pj_pool_calloc_imp(file, line, pool, 1, sz); 188 185 } 189 186 190 187 191 #endif /* PJ_POOL_DEBUG */ 188 189 #endif /* PJ_HAS_POOL_ALT_API */
Note: See TracChangeset
for help on using the changeset viewer.