Changeset 232


Ignore:
Timestamp:
Feb 26, 2006 9:18:42 PM (18 years ago)
Author:
bennylp
Message:

Added mutex protection for caching pool

Location:
pjproject/trunk/pjlib
Files:
2 edited

Legend:

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

    r69 r232  
    543543     */ 
    544544    pj_list         used_list; 
     545 
     546    /** 
     547     * Internal pool. 
     548     */ 
     549    pj_pool_t      *pool; 
     550 
     551    /** 
     552     * Mutex. 
     553     */ 
     554    pj_mutex_t     *mutex; 
    545555}; 
    546556 
  • pjproject/trunk/pjlib/src/pj/pool_caching.c

    r108 r232  
    5757    cp->factory.release_pool = &cpool_release_pool; 
    5858    cp->factory.dump_status = &cpool_dump_status; 
     59 
     60    cp->pool = pj_pool_create_int(&cp->factory, "cachingpool", 128,  
     61                                  0, NULL); 
     62    i = pj_mutex_create_simple(cp->pool, "cachingpool", &cp->mutex); 
    5963} 
    6064 
     
    8589        pool = next; 
    8690    } 
     91 
     92    pj_mutex_destroy(cp->mutex); 
    8793} 
    8894 
     
    98104 
    99105    PJ_CHECK_STACK(); 
     106 
     107    pj_mutex_lock(cp->mutex); 
    100108 
    101109    /* Use pool factory's policy when callback is NULL */ 
     
    124132        pool = pj_pool_create_int(&cp->factory, name, initial_size,  
    125133                                  increment_sz, callback); 
    126         if (!pool) 
     134        if (!pool) { 
     135            pj_mutex_unlock(cp->mutex); 
    127136            return NULL; 
     137        } 
    128138 
    129139    } else { 
     
    146156    /* Increment used count. */ 
    147157    ++cp->used_count; 
     158 
     159    pj_mutex_unlock(cp->mutex); 
    148160    return pool; 
    149161} 
     
    155167 
    156168    PJ_CHECK_STACK(); 
     169 
     170    pj_mutex_lock(cp->mutex); 
    157171 
    158172    /* Erase from the used list. */ 
     
    170184    { 
    171185        pj_pool_destroy_int(pool); 
     186        pj_mutex_unlock(cp->mutex); 
    172187        return; 
    173188    } 
     
    189204        /* Something has gone wrong with the pool. */ 
    190205        pj_pool_destroy_int(pool); 
     206        pj_mutex_unlock(cp->mutex); 
    191207        return; 
    192208    } 
     
    194210    pj_list_insert_after(&cp->free_list[i], pool); 
    195211    cp->capacity += pool->capacity; 
     212 
     213    pj_mutex_unlock(cp->mutex); 
    196214} 
    197215 
     
    200218#if PJ_LOG_MAX_LEVEL >= 3 
    201219    pj_caching_pool *cp = (pj_caching_pool*)factory; 
     220 
     221    pj_mutex_lock(cp->mutex); 
     222 
    202223    PJ_LOG(3,("cachpool", " Dumping caching pool:")); 
    203224    PJ_LOG(3,("cachpool", "   Capacity=%u, max_capacity=%u, used_cnt=%u", \ 
     
    219240                              total_used * 100 / total_capacity)); 
    220241    } 
     242 
     243    pj_mutex_unlock(cp->mutex); 
    221244#else 
    222245    PJ_UNUSED_ARG(factory); 
Note: See TracChangeset for help on using the changeset viewer.