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 |
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 |