apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stri...@apache.org
Subject cvs commit: apr/memory/unix apr_pools.c
Date Sat, 15 Dec 2001 11:13:46 GMT
striker     01/12/15 03:13:46

  Modified:    memory/unix apr_pools.c
  Log:
  Bring the code more into the style of the rest of APR.  Replaced
  the LOCK/UNLOCK macros with actual code.  Previously, with some
  of the extra #if APR_HAS_THREADS in place, it didn't feel right
  to use the macros anymore.
  
  Revision  Changes    Path
  1.123     +53 -40    apr/memory/unix/apr_pools.c
  
  Index: apr_pools.c
  ===================================================================
  RCS file: /home/cvs/apr/memory/unix/apr_pools.c,v
  retrieving revision 1.122
  retrieving revision 1.123
  diff -u -r1.122 -r1.123
  --- apr_pools.c	2001/12/14 20:14:09	1.122
  +++ apr_pools.c	2001/12/15 11:13:45	1.123
  @@ -90,23 +90,6 @@
   
   #define APR_ALIGN_DEFAULT(size) APR_ALIGN(size, 8)
   
  -#if APR_HAS_THREADS
  -#define LOCK(mutex) \
  -    do { \
  -        if (mutex) \
  -            apr_thread_mutex_lock(mutex); \
  -    } while(0)
  -
  -#define UNLOCK(mutex) \
  -    do { \
  -        if (mutex) \
  -            apr_thread_mutex_unlock(mutex); \
  -    } while(0)
  -#else
  -#define LOCK(mutex)
  -#define UNLOCK(mutex)
  -#endif
  -
   /*
    * Structures
    */
  @@ -126,8 +109,6 @@
       apr_uint32_t        max_index;
   #if APR_HAS_THREADS
       apr_thread_mutex_t *mutex;
  -#else
  -    void               *mutex;
   #endif
       apr_pool_t         *owner;
       node_t             *free[MAX_INDEX];
  @@ -169,7 +150,9 @@
   static apr_byte_t   global_allocator_initialized = 0;
   static allocator_t  global_allocator = { 
       0,          /* max_index */
  +#if APR_HAS_THREADS
       NULL,       /* mutex */
  +#endif
       NULL,       /* owner */
       { NULL }    /* free[0] */
   };
  @@ -199,8 +182,11 @@
        * our node will fit into.
        */
       if (index <= allocator->max_index) {
  -        LOCK(allocator->mutex);
  -
  +#if APR_HAS_THREADS
  +        if (allocator->mutex)
  +            apr_thread_mutex_lock(allocator->mutex);
  +#endif
  +        
           /* Walk the free list to see if there are
            * any nodes on it of the requested size
            *
  @@ -237,19 +223,28 @@
               
               node->next = NULL;
   
  -            UNLOCK(allocator->mutex);
  +#if APR_HAS_THREADS
  +            if (allocator->mutex)
  +                apr_thread_mutex_unlock(allocator->mutex);
  +#endif
   
               return node;
           }
   
  -        UNLOCK(allocator->mutex);
  +#if APR_HAS_THREADS
  +        if (allocator->mutex)
  +            apr_thread_mutex_unlock(allocator->mutex);
  +#endif
       }
   
       /* If we found nothing, seek the sink (at index 0), if
        * it is not empty.
        */
       else if (allocator->free[0]) {
  -        LOCK(allocator->mutex);
  +#if APR_HAS_THREADS
  +        if (allocator->mutex)
  +            apr_thread_mutex_lock(allocator->mutex);
  +#endif
   
           /* Walk the free list to see if there are
            * any nodes on it of the requested size
  @@ -262,12 +257,18 @@
               *ref = node->next;
               node->next = NULL;
               
  -            UNLOCK(allocator->mutex);
  +#if APR_HAS_THREADS
  +            if (allocator->mutex)
  +                apr_thread_mutex_unlock(allocator->mutex);
  +#endif
   
               return node;
           }
           
  -        UNLOCK(allocator->mutex);
  +#if APR_HAS_THREADS
  +        if (allocator->mutex)
  +            apr_thread_mutex_unlock(allocator->mutex);
  +#endif
       }
       
       /* If we haven't got a suitable node, malloc a new one
  @@ -289,7 +290,10 @@
       node_t *next;
       apr_uint32_t index, max_index;
   
  -    LOCK(allocator->mutex);
  +#if APR_HAS_THREADS
  +    if (allocator->mutex)
  +        apr_thread_mutex_lock(allocator->mutex);
  +#endif
   
       max_index = allocator->max_index;
   
  @@ -321,7 +325,10 @@
   
       allocator->max_index = max_index;
   
  -    UNLOCK(allocator->mutex);
  +#if APR_HAS_THREADS
  +    if (allocator->mutex)
  +        apr_thread_mutex_unlock(allocator->mutex);
  +#endif
   }
   
   APR_DECLARE(void *) apr_palloc(apr_pool_t *pool, apr_size_t size)
  @@ -453,11 +460,6 @@
   {
       node_t *node, *active, **ref;
       allocator_t *allocator;
  -#if APR_HAS_THREADS
  -    apr_thread_mutex_t *mutex;
  -#else
  -    void *mutex;
  -#endif
       apr_uint32_t index;
   
       /* Destroy the subpools.  The subpools will detach themselve from 
  @@ -474,14 +476,20 @@
   
       /* Remove the pool from the parents child list */
       if (pool->parent) {
  -        mutex = pool->parent->allocator->mutex;
  +#if APR_HAS_THREADS
  +        apr_thread_mutex_t *mutex;
   
  -        LOCK(mutex);
  +        if ((mutex = pool->parent->allocator->mutex) != NULL)
  +            apr_thread_mutex_lock(mutex);
  +#endif
   
           if ((*pool->ref = pool->sibling) != NULL)
               pool->sibling->ref = pool->ref;
   
  -        UNLOCK(mutex);
  +#if APR_HAS_THREADS
  +        if (mutex)
  +            apr_thread_mutex_unlock(mutex);
  +#endif
       }
       
       /* Reset the active block */
  @@ -568,6 +576,7 @@
   #if APR_HAS_THREADS
           if ((flags & APR_POOL_FLOCK) == APR_POOL_FLOCK) {
               apr_status_t rv;
  +
               if ((rv = apr_thread_mutex_create(&allocator->mutex, 
                       APR_THREAD_MUTEX_DEFAULT, pool)) != APR_SUCCESS) {
                   node_free(allocator, node);
  @@ -593,15 +602,20 @@
       }
   
       if ((pool->parent = parent) != NULL) {
  -        LOCK(allocator->mutex);
  -
  +#if APR_HAS_THREADS
  +        if (allocator->mutex)
  +            apr_thread_mutex_lock(allocator->mutex);
  +#endif
           if ((pool->sibling = parent->child) != NULL)
               pool->sibling->ref = &pool->sibling;
   
           parent->child = pool;
           pool->ref = &parent->child;
   
  -        UNLOCK(allocator->mutex);
  +#if APR_HAS_THREADS
  +        if (allocator->mutex)
  +            apr_thread_mutex_unlock(allocator->mutex);
  +#endif
       }
       else {
           pool->sibling = NULL;
  @@ -1099,4 +1113,3 @@
   
   #endif /* WIN32 */
   }
  -
  
  
  

Mime
View raw message