Changeset 364


Ignore:
Timestamp:
Mar 30, 2006 3:56:01 PM (18 years ago)
Author:
bennylp
Message:

Added ability to have custom pool backend (needed for pool debugging facility)

Location:
pjproject/trunk/pjlib
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjlib/include/pj/config.h

    r354 r364  
    209209#endif 
    210210 
    211 /** 
    212  * Pool debugging. 
     211 
     212/** 
     213 * If pool debugging is used, then each memory allocation from the pool 
     214 * will call malloc(), and pool will release all memory chunks when it 
     215 * is destroyed. This works better when memory verification programs 
     216 * such as Rational Purify is used. 
    213217 * 
    214218 * Default: 0 
     
    217221#  define PJ_POOL_DEBUG             0 
    218222#endif 
     223 
     224 
     225/** 
     226 * Do we have alternate pool implementation? 
     227 * 
     228 * Default: 0 
     229 */ 
     230#ifndef PJ_HAS_POOL_ALT_API 
     231#   define PJ_HAS_POOL_ALT_API      PJ_POOL_DEBUG 
     232#endif 
     233 
    219234 
    220235/** 
     
    261276#   endif 
    262277#endif 
     278 
     279 
     280/** 
     281 * If PJ_IOQUEUE_HAS_SAFE_UNREG macro is defined, then ioqueue will do more 
     282 * things to ensure thread safety of handle unregistration operation by 
     283 * employing reference counter to each handle. 
     284 * 
     285 * In addition, the ioqueue will preallocate memory for the handles,  
     286 * according to the maximum number of handles that is specified during  
     287 * ioqueue creation. 
     288 * 
     289 * All applications would normally want this enabled, but you may disable 
     290 * this if: 
     291 *  - there is no dynamic unregistration to all ioqueues. 
     292 *  - there is no threading, or there is no preemptive multitasking. 
     293 * 
     294 * Default: 1 
     295 */ 
     296#ifndef PJ_IOQUEUE_HAS_SAFE_UNREG 
     297#   define PJ_IOQUEUE_HAS_SAFE_UNREG    1 
     298#endif 
     299 
     300 
     301/** 
     302 * When safe unregistration (PJ_IOQUEUE_HAS_SAFE_UNREG) is configured in 
     303 * ioqueue, the PJ_IOQUEUE_KEY_FREE_DELAY macro specifies how long the 
     304 * ioqueue key is kept in closing state before it can be reused. 
     305 * 
     306 * The value is in miliseconds. 
     307 * 
     308 * Default: 500 msec. 
     309 */ 
     310#ifndef PJ_IOQUEUE_KEY_FREE_DELAY 
     311#   define PJ_IOQUEUE_KEY_FREE_DELAY    500 
     312#endif 
     313 
    263314 
    264315/** 
  • pjproject/trunk/pjlib/include/pj/pool.h

    r232 r364  
    1717 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  
    1818 */ 
     19 
     20#include <pj/list.h> 
     21 
     22/* See if we use pool's alternate API. 
     23 * The alternate API is used e.g. to implement pool debugging. 
     24 */ 
     25#if PJ_HAS_POOL_ALT_API 
     26#  include <pj/pool_alt.h> 
     27#endif 
     28 
     29 
    1930#ifndef __PJ_POOL_H__ 
    2031#define __PJ_POOL_H__ 
     
    2435 * @brief Memory Pool. 
    2536 */ 
    26  
    27 #include <pj/list.h> 
    2837 
    2938PJ_BEGIN_DECL 
     
    475484 
    476485/** 
     486 * Dump pool factory state. 
     487 * @param pf        The pool factory. 
     488 * @param detail    Detail state required. 
     489 */ 
     490PJ_INLINE(void) pj_pool_factory_dump( pj_pool_factory *pf, 
     491                                      pj_bool_t detail ) 
     492{ 
     493    (*pf->dump_status)(pf, detail); 
     494} 
     495 
     496/** 
    477497 *  @}  // PJ_POOL_FACTORY 
    478498 */ 
  • pjproject/trunk/pjlib/src/pj/config.c

    r315 r364  
    2222 
    2323static const char *id = "config.c"; 
    24 const char *PJ_VERSION = "0.5.4.1"; 
     24const char *PJ_VERSION = "0.5.4.5"; 
    2525 
    2626PJ_DEF(void) pj_dump_config(void) 
     
    4444    PJ_LOG(3, (id, " PJ_LOG_USE_STACK_BUFFER   : %d", PJ_LOG_USE_STACK_BUFFER)); 
    4545    PJ_LOG(3, (id, " PJ_POOL_DEBUG             : %d", PJ_POOL_DEBUG)); 
     46    PJ_LOG(3, (id, " PJ_HAS_POOL_ALT_API       : %d", PJ_HAS_POOL_ALT_API)); 
    4647    PJ_LOG(3, (id, " PJ_HAS_TCP                : %d", PJ_HAS_TCP)); 
    4748    PJ_LOG(3, (id, " PJ_MAX_HOSTNAME           : %d", PJ_MAX_HOSTNAME)); 
    4849    PJ_LOG(3, (id, " ioqueue type              : %s", pj_ioqueue_name())); 
    4950    PJ_LOG(3, (id, " PJ_IOQUEUE_MAX_HANDLES    : %d", PJ_IOQUEUE_MAX_HANDLES)); 
     51    PJ_LOG(3, (id, " PJ_IOQUEUE_HAS_SAFE_UNREG : %d", PJ_IOQUEUE_HAS_SAFE_UNREG)); 
    5052    PJ_LOG(3, (id, " PJ_HAS_THREADS            : %d", PJ_HAS_THREADS)); 
    5153    PJ_LOG(3, (id, " PJ_LOG_USE_STACK_BUFFER   : %d", PJ_LOG_USE_STACK_BUFFER)); 
  • pjproject/trunk/pjlib/src/pj/pool.c

    r315 r364  
    2323#include <pj/os.h> 
    2424 
     25#if !PJ_HAS_POOL_ALT_API 
     26 
     27 
    2528/* Include inline definitions when inlining is disabled. */ 
    2629#if !PJ_FUNCTIONS_ARE_INLINED 
     
    262265 
    263266 
     267#endif  /* PJ_HAS_POOL_ALT_API */ 
     268 
  • pjproject/trunk/pjlib/src/pj/pool_caching.c

    r338 r364  
    2323#include <pj/os.h> 
    2424 
     25#if !PJ_HAS_POOL_ALT_API 
     26 
    2527static pj_pool_t* cpool_create_pool(pj_pool_factory *pf,  
    2628                                    const char *name, 
     
    164166{ 
    165167    pj_caching_pool *cp = (pj_caching_pool*)pf; 
     168    unsigned pool_capacity; 
    166169    int i; 
    167170 
     
    175178    /* Decrement used count. */ 
    176179    --cp->used_count; 
     180 
     181    pool_capacity = pj_pool_get_capacity(pool); 
    177182 
    178183    /* Destroy the pool if the size is greater than our size or if the total 
     
    180185     * maximum capacity. 
    181186   . */ 
    182     if (pool->capacity > pool_sizes[PJ_CACHING_POOL_ARRAY_SIZE-1] || 
    183         cp->capacity + pool->capacity > cp->max_capacity) 
     187    if (pool_capacity > pool_sizes[PJ_CACHING_POOL_ARRAY_SIZE-1] || 
     188        cp->capacity + pool_capacity > cp->max_capacity) 
    184189    { 
    185190        pj_pool_destroy_int(pool); 
     
    190195    /* Reset pool. */ 
    191196    PJ_LOG(6, (pool->obj_name, "recycle(): cap=%d, used=%d(%d%%)",  
    192                pool->capacity, pj_pool_get_used_size(pool),  
    193                pj_pool_get_used_size(pool)*100/pool->capacity)); 
     197               pool_capacity, pj_pool_get_used_size(pool),  
     198               pj_pool_get_used_size(pool)*100/pool_capacity)); 
    194199    pj_pool_reset(pool); 
    195200 
     
    197202     * Otherwise put the pool in our recycle list. 
    198203     */ 
    199     for (i=0; i < PJ_CACHING_POOL_ARRAY_SIZE && pool_sizes[i] != pool->capacity; ++i) 
     204    for (i=0; i < PJ_CACHING_POOL_ARRAY_SIZE && pool_sizes[i] != pool_capacity; ++i) 
    200205        ; 
    201206 
     
    209214 
    210215    pj_list_insert_after(&cp->free_list[i], pool); 
    211     cp->capacity += pool->capacity; 
     216    cp->capacity += pool_capacity; 
    212217 
    213218    pj_mutex_unlock(cp->mutex); 
     
    229234        PJ_LOG(3,("cachpool", "  Dumping all active pools:")); 
    230235        while (pool != (void*)&cp->used_list) { 
    231             PJ_LOG(3,("cachpool", "   %12s: %8d of %8d (%d%%) used", pool->obj_name,  
    232                                   pj_pool_get_used_size(pool), pool->capacity, 
    233                                   pj_pool_get_used_size(pool)*100/pool->capacity)); 
     236            unsigned pool_capacity = pj_pool_get_capacity(pool); 
     237            PJ_LOG(3,("cachpool", "   %12s: %8d of %8d (%d%%) used",  
     238                                  pj_pool_getobjname(pool),  
     239                                  pj_pool_get_used_size(pool),  
     240                                  pool_capacity, 
     241                                  pj_pool_get_used_size(pool)*100/pool_capacity)); 
    234242            total_used += pj_pool_get_used_size(pool); 
    235             total_capacity += pool->capacity; 
     243            total_capacity += pool_capacity; 
    236244            pool = pool->next; 
    237245        } 
     
    247255#endif 
    248256} 
     257 
     258#endif  /* PJ_HAS_POOL_ALT_API */ 
     259 
  • pjproject/trunk/pjlib/src/pj/pool_policy_malloc.c

    r66 r364  
    2121#include <pj/os.h> 
    2222#include <pj/compat/malloc.h> 
     23 
     24#if !PJ_HAS_POOL_ALT_API 
    2325 
    2426/* 
     
    6163    0 
    6264}; 
     65 
     66#endif  /* PJ_HAS_POOL_ALT_API */ 
Note: See TracChangeset for help on using the changeset viewer.