apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wr...@apache.org
Subject cvs commit: apr-util/misc apr_rmm.c
Date Tue, 08 Jan 2002 06:19:15 GMT
wrowe       02/01/07 22:19:15

  Modified:    include  apr_rmm.h
               misc     apr_rmm.c
  Log:
    Add an apr_anylock_t to the rmm create/attach fns.  Only the user of the
    apr_rmm knows if no lock is required, if only threads of a single process
    will perform allocations, or if all processes will be allocating and
    freeing blocks simultaniously.  So the caller must provide a lock, if
    desired.  We will protect against lock NULL args by creating a nulllock.
  
  Revision  Changes    Path
  1.3       +8 -4      apr-util/include/apr_rmm.h
  
  Index: apr_rmm.h
  ===================================================================
  RCS file: /home/cvs/apr-util/include/apr_rmm.h,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- apr_rmm.h	5 Jan 2002 13:44:11 -0000	1.2
  +++ apr_rmm.h	8 Jan 2002 06:19:15 -0000	1.3
  @@ -68,6 +68,7 @@
   #include "apr_pools.h"
   #include "apr_errno.h"
   #include "apu.h"
  +#include "apr_anylock.h"
   
   #ifdef __cplusplus
   extern "C" {
  @@ -82,12 +83,14 @@
   /**
    * Initialize a relocatable memory block to be managed by the apr_rmm API.
    * @param rmm The relocatable memory block
  + * @param lock An apr_anylock_t of the appropriate type of lock
    * @param membuf The block of relocateable memory to be managed
    * @param memsize The size of relocateable memory block to be managed
    * @param cont The pool to use for local storage and management
    */
  -APU_DECLARE(apr_status_t) apr_rmm_init(apr_rmm_t **rmm, void* membuf,
  -                                       apr_size_t memsize, apr_pool_t *cont);
  +APU_DECLARE(apr_status_t) apr_rmm_init(apr_rmm_t **rmm, apr_anylock_t *lock,
  +                                       void* membuf, apr_size_t memsize, 
  +                                       apr_pool_t *cont);
   
   /**
    * Destroy a managed memory block.
  @@ -98,11 +101,12 @@
   /**
    * Attach to a relocatable memory block already managed by the apr_rmm API.
    * @param rmm The relocatable memory block
  + * @param lock An apr_anylock_t of the appropriate type of lock
    * @param membuf The block of relocateable memory already under management
    * @param cont The pool to use for local storage and management
    */
  -APU_DECLARE(apr_status_t) apr_rmm_attach(apr_rmm_t **rmm, void* membuf,
  -                                         apr_pool_t *cont);
  +APU_DECLARE(apr_status_t) apr_rmm_attach(apr_rmm_t **rmm, apr_anylock_t *lock,
  +                                         void* membuf, apr_pool_t *cont);
   
   /**
    * Detach from the managed block of memory.
  
  
  
  1.3       +57 -7     apr-util/misc/apr_rmm.c
  
  Index: apr_rmm.c
  ===================================================================
  RCS file: /home/cvs/apr-util/misc/apr_rmm.c,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- apr_rmm.c	5 Jan 2002 13:44:11 -0000	1.2
  +++ apr_rmm.c	8 Jan 2002 06:19:15 -0000	1.3
  @@ -76,6 +76,7 @@
       apr_pool_t *p;
       rmm_hdr_block_t *base;
       apr_size_t size;
  +    apr_anylock_t lock;
   };
   
   #define MIN_BLK_SIZE 128
  @@ -202,15 +203,27 @@
       }
   }
   
  -APU_DECLARE(apr_status_t) apr_rmm_init(apr_rmm_t **rmm, void *base, apr_size_t size,
  +APU_DECLARE(apr_status_t) apr_rmm_init(apr_rmm_t **rmm, apr_anylock_t *lock, 
  +                                       void *base, apr_size_t size,
                                          apr_pool_t *p)
   {
  +    apr_status_t rv;
       rmm_block_t *blk;
  +    apr_anylock_t nulllock;
  +    
  +    if (!lock) {
  +        nulllock.type = apr_anylock_none;
  +        nulllock.lock.rw = NULL;
  +        lock = &nulllock;
  +    }
  +    if ((rv = APR_ANYLOCK_LOCK(lock)) != APR_SUCCESS)
  +        return rv;
   
       (*rmm) = (apr_rmm_t *)apr_pcalloc(p, sizeof(apr_rmm_t));
       (*rmm)->p = p;
       (*rmm)->base = base;
       (*rmm)->size = size;
  +    (*rmm)->lock = *lock;
   
       (*rmm)->base->abssize = size;
       (*rmm)->base->firstused = 0;
  @@ -222,13 +235,18 @@
       blk->prev = 0;
       blk->next = 0;
   
  +    APR_ANYLOCK_UNLOCK(lock);
       return APR_SUCCESS;
   }
   
   APU_DECLARE(apr_status_t) apr_rmm_destroy(apr_rmm_t *rmm)
   {
  +    apr_status_t rv;
       rmm_block_t *blk;
   
  +    if ((rv = APR_ANYLOCK_LOCK(&rmm->lock)) != APR_SUCCESS) {
  +        return rv;
  +    }
       /* Blast it all --- no going back :) */
       if (rmm->base->firstused) {
           apr_rmm_off_t this = rmm->base->firstused;
  @@ -250,42 +268,65 @@
       }
       rmm->base->abssize = 0;
       rmm->size = 0;
  +
  +    APR_ANYLOCK_UNLOCK(&rmm->lock);
       return APR_SUCCESS;
   }
   
  -APU_DECLARE(apr_status_t) apr_rmm_attach(apr_rmm_t **rmm, void *base, 
  -                                         apr_pool_t *p)
  +APU_DECLARE(apr_status_t) apr_rmm_attach(apr_rmm_t **rmm, apr_anylock_t *lock,
  +                                         void *base, apr_pool_t *p)
   {
  +    apr_anylock_t nulllock;
  +
  +    if (!lock) {
  +        nulllock.type = apr_anylock_none;
  +        nulllock.lock.rw = NULL;
  +        lock = &nulllock;
  +    }
  +
       /* sanity would be good here */
       (*rmm) = (apr_rmm_t *)apr_pcalloc(p, sizeof(apr_rmm_t));
       (*rmm)->p = p;
       (*rmm)->base = base;
       (*rmm)->size = (*rmm)->base->abssize;
  -
  +    (*rmm)->lock = *lock;
       return APR_SUCCESS;
   }
   
   APU_DECLARE(apr_status_t) apr_rmm_detach(apr_rmm_t *rmm) 
   {
  -    /* A noop until we introduce locking/refcounts */
  +    /* A noop until we introduce locked/refcounts */
       return APR_SUCCESS;
   }
   
   APU_DECLARE(apr_rmm_off_t) apr_rmm_malloc(apr_rmm_t *rmm, apr_size_t reqsize)
   {
  -    apr_rmm_off_t this = find_block_of_size(rmm, reqsize + sizeof(rmm_block_t));
  +    apr_status_t rv;
  +    apr_rmm_off_t this;
  +    
  +    if ((rv = APR_ANYLOCK_LOCK(&rmm->lock)) != APR_SUCCESS)
  +        return rv;
  +
  +    this = find_block_of_size(rmm, reqsize + sizeof(rmm_block_t));
   
       if (this) {
           move_block(rmm, this, 0);
           this += sizeof(rmm_block_t);
       }
   
  +    APR_ANYLOCK_UNLOCK(&rmm->lock);
       return this;
   }
   
   APU_DECLARE(apr_rmm_off_t) apr_rmm_calloc(apr_rmm_t *rmm, apr_size_t reqsize)
   {
  -    apr_rmm_off_t this = find_block_of_size(rmm, reqsize + sizeof(rmm_block_t));
  +    apr_status_t rv;
  +    apr_rmm_off_t this;
  +        
  +    if ((rv = APR_ANYLOCK_LOCK(&rmm->lock)) != APR_SUCCESS)
  +        return rv;
  +
  +    this = find_block_of_size(rmm, reqsize + sizeof(rmm_block_t));
   
       if (this) {
           move_block(rmm, this, 0);
  @@ -293,11 +334,13 @@
           memset((char*)rmm->base + this, 0, reqsize);
       }
   
  +    APR_ANYLOCK_UNLOCK(&rmm->lock);
       return this;
   }
   
   APU_DECLARE(apr_status_t) apr_rmm_free(apr_rmm_t *rmm, apr_rmm_off_t this)
   {
  +    apr_status_t rv;
       struct rmm_block_t *blk;
   
       /* A little sanity check is always healthy, especially here.
  @@ -311,14 +354,19 @@
   
       blk = (rmm_block_t*)((char*)rmm->base + this);
   
  +    if ((rv = APR_ANYLOCK_LOCK(&rmm->lock)) != APR_SUCCESS) {
  +        return rv;
  +    }
       if (blk->prev) {
           struct rmm_block_t *prev = (rmm_block_t*)((char*)rmm->base + blk->prev);
           if (prev->next != this) {
  +            APR_ANYLOCK_UNLOCK(&rmm->lock);
               return APR_EINVAL;
           }
       }
       else {
           if (rmm->base->firstused != this) {
  +            APR_ANYLOCK_UNLOCK(&rmm->lock);
               return APR_EINVAL;
           }
       }
  @@ -326,6 +374,7 @@
       if (blk->next) {
           struct rmm_block_t *next = (rmm_block_t*)((char*)rmm->base + blk->next);
           if (next->prev != this) {
  +            APR_ANYLOCK_UNLOCK(&rmm->lock);
               return APR_EINVAL;
           }
       }
  @@ -334,6 +383,7 @@
        */
       move_block(rmm, this, 1);
       
  +    APR_ANYLOCK_UNLOCK(&rmm->lock);
       return APR_SUCCESS;
   }
   
  
  
  

Mime
View raw message