Ignore:
Timestamp:
Jul 9, 2006 10:05:46 AM (16 years ago)
Author:
bennylp
Message:

Added feature to report peak memory used in caching pool

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjlib/src/pj/pool_caching.c

    r588 r594  
    3232static void cpool_release_pool(pj_pool_factory *pf, pj_pool_t *pool); 
    3333static void cpool_dump_status(pj_pool_factory *factory, pj_bool_t detail ); 
     34static pj_bool_t cpool_on_block_alloc(pj_pool_factory *f, pj_size_t sz); 
     35static void cpool_on_block_free(pj_pool_factory *f, pj_size_t sz); 
     36 
    3437 
    3538static pj_size_t pool_sizes[PJ_CACHING_POOL_ARRAY_SIZE] =  
     
    6467    cp->factory.release_pool = &cpool_release_pool; 
    6568    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; 
    6671 
    6772    cp->pool = pj_pool_create_int(&cp->factory, "cachingpool", 256,  
     
    274279} 
    275280 
     281 
     282static 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 
     299static 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 
    276309#endif  /* PJ_HAS_POOL_ALT_API */ 
    277310 
Note: See TracChangeset for help on using the changeset viewer.