src/server/util/pool.c

changeset 415
d938228c382e
parent 339
f4a34b0869c7
equal deleted inserted replaced
414:99a34860c105 415:d938228c382e
76 static pool_config_t pool_config = POOL_CONFIG_INIT; 76 static pool_config_t pool_config = POOL_CONFIG_INIT;
77 77
78 /* Pool global statistics */ 78 /* Pool global statistics */
79 static pool_global_stats_t pool_global_stats; 79 static pool_global_stats_t pool_global_stats;
80 80
81 /* ucx allocator pool class */
82 static cx_allocator_class pool_allocator_class = {
83 (void *(*)(void *,size_t )) pool_malloc,
84 (void *(*)(void *,void *, size_t )) pool_realloc,
85 (void *(*)(void *,size_t ,size_t )) pool_calloc,
86 (void (*)(void *, void *))pool_free
87 };
88
81 static int 89 static int
82 pool_internal_init() 90 pool_internal_init()
83 { 91 {
84 //if (pool_global_stats.lock == NULL) { 92 //if (pool_global_stats.lock == NULL) {
85 // pool_global_stats.lock = PR_NewLock(); // TODO: remove 93 // pool_global_stats.lock = PR_NewLock(); // TODO: remove
130 } 138 }
131 139
132 pool_internal_init(); 140 pool_internal_init();
133 141
134 return REQ_PROCEED; 142 return REQ_PROCEED;
143 }
144
145 CxAllocator* pool_allocator(pool_handle_t *pool) {
146 return &((pool_t *)pool)->allocator;
135 } 147 }
136 148
137 static block_t * 149 static block_t *
138 _create_block(pool_t *pool, int size) 150 _create_block(pool_t *pool, int size)
139 { 151 {
248 * before pool_init can be called... 260 * before pool_init can be called...
249 */ 261 */
250 //if (pool_global_stats.lock == NULL) { // TODO: remove 262 //if (pool_global_stats.lock == NULL) { // TODO: remove
251 // pool_internal_init(); 263 // pool_internal_init();
252 //} 264 //}
253 265
266 newpool->allocator.cl = &pool_allocator_class;
267 newpool->allocator.data = newpool;
268
254 newpool->used_blocks = NULL; 269 newpool->used_blocks = NULL;
255 newpool->free_blocks = NULL; 270 newpool->free_blocks = NULL;
256 newpool->free_size = 0; 271 newpool->free_size = 0;
257 newpool->free_num = 0; 272 newpool->free_num = 0;
258 newpool->size = 0; 273 newpool->size = 0;
716 return &pool->stats; 731 return &pool->stats;
717 } 732 }
718 #endif /* PER_POOL_STATISTICS */ 733 #endif /* PER_POOL_STATISTICS */
719 734
720 // new 735 // new
721 sstr_t sstrdup_pool(pool_handle_t *pool, sstr_t s) { 736 cxmutstr cx_strdup_pool(pool_handle_t *pool, cxmutstr s) {
722 sstr_t newstring; 737 cxmutstr newstring;
723 newstring.ptr = (char*)pool_malloc(pool, s.length + 1); 738 newstring.ptr = (char*)pool_malloc(pool, s.length + 1);
724 if (newstring.ptr != NULL) { 739 if (newstring.ptr != NULL) {
725 newstring.length = s.length; 740 newstring.length = s.length;
726 newstring.ptr[newstring.length] = 0; 741 newstring.ptr[newstring.length] = 0;
727 742

mercurial