Changeset 594
- Timestamp:
- Jul 9, 2006 10:05:46 AM (18 years ago)
- Location:
- pjproject/trunk/pjlib
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib/include/pj/pool.h
r588 r594 450 450 */ 451 451 void (*dump_status)( pj_pool_factory *factory, pj_bool_t detail ); 452 453 /** 454 * This is optional callback to be called by allocation policy when 455 * it allocates a new memory block. The factory may use this callback 456 * for example to keep track of the total number of memory blocks 457 * currently allocated by applications. 458 * 459 * @param factory The pool factory. 460 * @param size Size requested by application. 461 * 462 * @return MUST return PJ_TRUE, otherwise the block 463 * allocation is cancelled. 464 */ 465 pj_bool_t (*on_block_alloc)(pj_pool_factory *factory, pj_size_t size); 466 467 /** 468 * This is optional callback to be called by allocation policy when 469 * it frees memory block. The factory may use this callback 470 * for example to keep track of the total number of memory blocks 471 * currently allocated by applications. 472 * 473 * @param factory The pool factory. 474 * @param size Size freed. 475 */ 476 void (*on_block_free)(pj_pool_factory *factory, pj_size_t size); 477 452 478 }; 453 479 … … 558 584 559 585 /** 586 * Total size of memory currently used by application. 587 */ 588 pj_size_t used_size; 589 590 /** 591 * The maximum size of memory used by application throughout the life 592 * of the caching pool. 593 */ 594 pj_size_t peak_used_size; 595 596 /** 560 597 * Lists of pools in the cache, indexed by pool size. 561 598 */ -
pjproject/trunk/pjlib/src/pj/pool_caching.c
r588 r594 32 32 static void cpool_release_pool(pj_pool_factory *pf, pj_pool_t *pool); 33 33 static void cpool_dump_status(pj_pool_factory *factory, pj_bool_t detail ); 34 static pj_bool_t cpool_on_block_alloc(pj_pool_factory *f, pj_size_t sz); 35 static void cpool_on_block_free(pj_pool_factory *f, pj_size_t sz); 36 34 37 35 38 static pj_size_t pool_sizes[PJ_CACHING_POOL_ARRAY_SIZE] = … … 64 67 cp->factory.release_pool = &cpool_release_pool; 65 68 cp->factory.dump_status = &cpool_dump_status; 69 cp->factory.on_block_alloc = &cpool_on_block_alloc; 70 cp->factory.on_block_free = &cpool_on_block_free; 66 71 67 72 cp->pool = pj_pool_create_int(&cp->factory, "cachingpool", 256, … … 274 279 } 275 280 281 282 static pj_bool_t cpool_on_block_alloc(pj_pool_factory *f, pj_size_t sz) 283 { 284 pj_caching_pool *cp = (pj_caching_pool*)f; 285 286 //Can't lock because mutex is not recursive 287 //if (cp->mutex) pj_mutex_lock(cp->mutex); 288 289 cp->used_size += sz; 290 if (cp->used_size > cp->peak_used_size) 291 cp->peak_used_size = cp->used_size; 292 293 //if (cp->mutex) pj_mutex_unlock(cp->mutex); 294 295 return PJ_TRUE; 296 } 297 298 299 static void cpool_on_block_free(pj_pool_factory *f, pj_size_t sz) 300 { 301 pj_caching_pool *cp = (pj_caching_pool*)f; 302 303 //pj_mutex_lock(cp->mutex); 304 cp->used_size -= sz; 305 //pj_mutex_unlock(cp->mutex); 306 } 307 308 276 309 #endif /* PJ_HAS_POOL_ALT_API */ 277 310 -
pjproject/trunk/pjlib/src/pj/pool_policy_malloc.c
r364 r594 31 31 static void *default_block_alloc(pj_pool_factory *factory, pj_size_t size) 32 32 { 33 void *p; 34 33 35 PJ_CHECK_STACK(); 34 PJ_UNUSED_ARG(factory);35 PJ_UNUSED_ARG(size);36 36 37 return malloc(size); 37 if (factory->on_block_alloc) { 38 int rc; 39 rc = factory->on_block_alloc(factory, size); 40 if (!rc) 41 return NULL; 42 } 43 44 p = malloc(size); 45 46 if (p == NULL) { 47 if (factory->on_block_free) 48 factory->on_block_free(factory, size); 49 } 50 51 return p; 38 52 } 39 53 40 static void default_block_free(pj_pool_factory *factory, void *mem, pj_size_t size) 54 static void default_block_free(pj_pool_factory *factory, void *mem, 55 pj_size_t size) 41 56 { 42 57 PJ_CHECK_STACK(); 43 PJ_UNUSED_ARG(factory); 44 PJ_UNUSED_ARG(size); 58 59 if (factory->on_block_free) 60 factory->on_block_free(factory, size); 45 61 46 62 free(mem);
Note: See TracChangeset
for help on using the changeset viewer.