Changeset 4567

Show
Ignore:
Timestamp:
02/10/07 01:42:57 (2 years ago)
Author:
morris
Message:

Add wi_pool_drain()

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • libwired/trunk/libwired/base/wi-pool.c

    r4511 r4567  
    7676static void                                                             _wi_pool_add_pool(wi_pool_t *); 
    7777static wi_pool_t *                                              _wi_pool_pool(void); 
     78static void                                                             _wi_pool_drain_pool(wi_pool_t *); 
    7879static void                                                             _wi_pool_remove_pool(wi_pool_t *); 
    79 static void                                                             _wi_pool_pop_pool(wi_pool_t *); 
    8080 
    8181 
     
    122122        _wi_pool_add_pool(pool); 
    123123         
    124         pool->array = wi_malloc(sizeof(_wi_pool_array_t)); 
    125          
    126124        return pool; 
    127125} 
     
    130128 
    131129static void _wi_pool_dealloc(wi_runtime_instance_t *instance) { 
    132         wi_pool_t                      *pool = instance; 
    133         _wi_pool_array_t       *array, *next_array; 
    134          
     130        wi_pool_t               *pool = instance; 
     131         
     132        _wi_pool_drain_pool(pool); 
    135133        _wi_pool_remove_pool(pool); 
    136         _wi_pool_pop_pool(pool); 
    137          
    138         for(array = pool->array; array; array = next_array) { 
    139                 next_array = array->next; 
    140                 wi_free(array); 
    141         } 
     134         
    142135} 
    143136 
     
    186179 
    187180 
     181static void _wi_pool_drain_pool(wi_pool_t *pool) { 
     182        wi_runtime_instance_t           **instances; 
     183        _wi_pool_array_t                        *array, *next_array; 
     184        wi_uinteger_t                           i, length; 
     185         
     186        for(array = pool->array; array; array = next_array) { 
     187                next_array      = array->next; 
     188                length          = array->length; 
     189                instances       = array->instances; 
     190                 
     191                for(i = 0; i < length; i++) 
     192                        wi_release(*instances++); 
     193                 
     194                wi_free(array); 
     195        } 
     196 
     197        pool->count = 0; 
     198        pool->array = NULL; 
     199} 
     200 
     201 
     202 
    188203static void _wi_pool_remove_pool(wi_pool_t *pool) { 
    189204        wi_thread_t                             *thread; 
     
    220235 
    221236 
    222 static void _wi_pool_pop_pool(wi_pool_t *pool) { 
    223         wi_runtime_instance_t           **instances; 
    224         _wi_pool_array_t                        *array; 
    225         wi_uinteger_t                           i, length; 
    226          
    227         for(array = pool->array; array; array = array->next) { 
    228                 length          = array->length; 
    229                 instances       = array->instances; 
    230                  
    231                 for(i = 0; i < length; i++) 
    232                         wi_release(*instances++); 
    233         } 
    234 
    235  
    236  
    237  
    238 #pragma mark - 
     237#pragma mark - 
     238 
     239void wi_pool_drain(wi_pool_t *pool) { 
     240        _wi_pool_drain_pool(pool); 
     241
     242 
     243 
    239244 
    240245wi_uinteger_t wi_pool_count(wi_pool_t *pool) { 
     
    263268        } 
    264269         
     270        if(!pool->array) 
     271                pool->array = wi_malloc(sizeof(_wi_pool_array_t)); 
     272         
    265273        array = pool->array; 
    266274         
  • libwired/trunk/libwired/base/wi-pool.h

    r4437 r4567  
    4141WI_EXPORT wi_pool_t *                           wi_pool_init(wi_pool_t *); 
    4242 
     43WI_EXPORT void                                          wi_pool_drain(wi_pool_t *); 
    4344WI_EXPORT wi_uinteger_t                         wi_pool_count(wi_pool_t *); 
    4445