apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jwool...@apache.org
Subject cvs commit: apr-util/include apr_buckets.h
Date Thu, 28 Aug 2003 05:48:29 GMT
jwoolley    2003/08/27 22:48:29

  Modified:    .        CHANGES
               buckets  apr_buckets_alloc.c
               include  apr_buckets.h
  Log:
  at long last, the bucket_alloc_create changes.
  
   * apr_bucket_alloc_create() now uses the apr_allocator_t from the pool
     that was passed in rather than creating its own.
   * added apr_bucket_alloc_create_ex() which takes an apr_allocator_t
     directly instead of an apr_pool_t.
   * either way, the apr_bucket_alloc_t itself is allocated from the
     apr_allocator_t, not palloc'ed.  so in the non _ex() case, the only
     thing the pool gains you is a cleanup.
  
  Reviewed by:	Jean-Jacques Clar, Sander Striker, Brad Nicholes
  
  Revision  Changes    Path
  1.117     +7 -0      apr-util/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/apr-util/CHANGES,v
  retrieving revision 1.116
  retrieving revision 1.117
  diff -u -d -u -r1.116 -r1.117
  --- CHANGES	28 Aug 2003 02:09:52 -0000	1.116
  +++ CHANGES	28 Aug 2003 05:48:29 -0000	1.117
  @@ -1,5 +1,12 @@
   Changes with APR-util 0.9.4
   
  +  *) Changed apr_bucket_alloc_create() so that it uses the allocator
  +     from the pool that was passed in rather than creating its own.
  +     Also, the bucket_allocator is now allocated from the apr_allocator_t
  +     rather than using apr_palloc().  Added apr_bucket_alloc_create_ex()
  +     which takes an apr_allocator_t* directly rather than an apr_pool_t*.
  +     [Cliff Woolley, Jean-Jacques Clar]
  +
     *) Added debugging consistency checks to the buckets code.  Add
        -DAPR_BUCKET_DEBUG to the build flags to enable.
        [Cliff Woolley]
  
  
  
  1.13      +20 -10    apr-util/buckets/apr_buckets_alloc.c
  
  Index: apr_buckets_alloc.c
  ===================================================================
  RCS file: /home/cvs/apr-util/buckets/apr_buckets_alloc.c,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -d -u -r1.12 -r1.13
  --- apr_buckets_alloc.c	28 Aug 2003 02:09:52 -0000	1.12
  +++ apr_buckets_alloc.c	28 Aug 2003 05:48:29 -0000	1.13
  @@ -80,37 +80,47 @@
   static apr_status_t alloc_cleanup(void *data)
   {
       apr_bucket_alloc_t *list = data;
  -    apr_allocator_t *allocator = list->allocator;
   
  -    apr_allocator_free(allocator, list->blocks);
  -    apr_allocator_destroy(allocator);
  +    apr_allocator_free(list->allocator, list->blocks);
       return APR_SUCCESS;
   }
   
   APU_DECLARE_NONSTD(apr_bucket_alloc_t *) apr_bucket_alloc_create(apr_pool_t *p)
   {
  -    apr_allocator_t *allocator;
  +    apr_allocator_t *allocator = apr_pool_allocator_get(p);
  +    apr_bucket_alloc_t *list = apr_bucket_alloc_create_ex(allocator);
  +
  +    list->pool = p;
  +    apr_pool_cleanup_register(list->pool, list, alloc_cleanup,
  +                              apr_pool_cleanup_null);
  +
  +    return list;
  +}
  +
  +APU_DECLARE_NONSTD(apr_bucket_alloc_t *) apr_bucket_alloc_create_ex(
  +                                             apr_allocator_t *allocator)
  +{
       apr_bucket_alloc_t *list;
       apr_memnode_t *block;
   
  -    apr_allocator_create(&allocator);
       block = apr_allocator_alloc(allocator, ALLOC_AMT);
       list = (apr_bucket_alloc_t *)block->first_avail;
  -    list->pool = p;
  +    list->pool = NULL;
       list->allocator = allocator;
       list->freelist = NULL;
       list->blocks = block;
       block->first_avail += APR_ALIGN_DEFAULT(sizeof(*list));
   
  -    apr_pool_cleanup_register(list->pool, list, alloc_cleanup,
  -                              apr_pool_cleanup_null);
  -
       return list;
   }
   
   APU_DECLARE_NONSTD(void) apr_bucket_alloc_destroy(apr_bucket_alloc_t *list)
   {
  -    apr_pool_cleanup_run(list->pool, list, alloc_cleanup);
  +    if (list->pool) {
  +        apr_pool_cleanup_kill(list->pool, list, alloc_cleanup);
  +    }
  +
  +    apr_allocator_free(list->allocator, list->blocks);
   }
   
   APU_DECLARE_NONSTD(void *) apr_bucket_alloc(apr_size_t size, 
  
  
  
  1.154     +19 -3     apr-util/include/apr_buckets.h
  
  Index: apr_buckets.h
  ===================================================================
  RCS file: /home/cvs/apr-util/include/apr_buckets.h,v
  retrieving revision 1.153
  retrieving revision 1.154
  diff -u -d -u -r1.153 -r1.154
  --- apr_buckets.h	28 Aug 2003 02:09:52 -0000	1.153
  +++ apr_buckets.h	28 Aug 2003 05:48:29 -0000	1.154
  @@ -965,12 +965,28 @@
   /*  *****  Bucket freelist functions *****  */
   /**
    * Create a bucket allocator.
  - * @param p Pool to allocate the allocator from [note: this is only
  - *          used to allocate internal structures of the allocator, NOT
  - *          to allocate the memory handed out by the allocator]
  + * @param p This pool's underlying apr_allocator_t is used to allocate memory
  + *          for the bucket allocator.  When the pool is destroyed, the bucket
  + *          allocator's cleanup routine will free all memory that has been
  + *          allocated from it.
  + * @remark  The reason the allocator gets its memory from the pool's
  + *          apr_allocator_t rather than from the pool itself is because
  + *          the bucket allocator will free large memory blocks back to the
  + *          allocator when it's done with them, thereby preventing memory
  + *          footprint growth that would occur if we allocated from the pool.
    * @warning The allocator must never be used by more than one thread at a time.
    */
   APU_DECLARE_NONSTD(apr_bucket_alloc_t *) apr_bucket_alloc_create(apr_pool_t *p);
  +
  +/**
  + * Create a bucket allocator.
  + * @param allocator This apr_allocator_t is used to allocate both the bucket
  + *          allocator and all memory handed out by the bucket allocator.  The
  + *          caller is responsible for destroying the bucket allocator and the
  + *          apr_allocator_t -- no automatic cleanups will happen.
  + * @warning The allocator must never be used by more than one thread at a time.
  + */
  +APU_DECLARE_NONSTD(apr_bucket_alloc_t *) apr_bucket_alloc_create_ex(apr_allocator_t *allocator);
   
   /**
    * Destroy a bucket allocator.
  
  
  

Mime
View raw message